diff --git a/homeassistant/components/cast/media_player.py b/homeassistant/components/cast/media_player.py index dc3d20188e7458131812152d1850c3363fec1b36..310431bb488320c3d1012a944b7ef7624238ff06 100644 --- a/homeassistant/components/cast/media_player.py +++ b/homeassistant/components/cast/media_player.py @@ -80,12 +80,7 @@ _LOGGER = logging.getLogger(__name__) CAST_SPLASH = "https://www.home-assistant.io/images/cast/splash.png" SUPPORT_CAST = ( - SUPPORT_PAUSE - | SUPPORT_PLAY - | SUPPORT_PLAY_MEDIA - | SUPPORT_STOP - | SUPPORT_TURN_OFF - | SUPPORT_TURN_ON + SUPPORT_PAUSE | SUPPORT_PLAY | SUPPORT_PLAY_MEDIA | SUPPORT_STOP | SUPPORT_TURN_OFF ) STATE_CASTING = "casting" @@ -694,6 +689,12 @@ class CastDevice(MediaPlayerEntity): support = SUPPORT_CAST media_status = self._media_status()[0] + if ( + self._chromecast + and self._chromecast.cast_type == pychromecast.const.CAST_TYPE_CHROMECAST + ): + support |= SUPPORT_TURN_ON + if ( self.cast_status and self.cast_status.volume_control_type != VOLUME_CONTROL_TYPE_FIXED diff --git a/tests/components/cast/conftest.py b/tests/components/cast/conftest.py index 5078e4d34ad035f99aecb1bdd82648779ae2525c..dce5db5116153c0ed43e6ac56398caf993f4a551 100644 --- a/tests/components/cast/conftest.py +++ b/tests/components/cast/conftest.py @@ -42,6 +42,7 @@ def pycast_mock(castbrowser_mock, castbrowser_constructor_mock): pycast_mock = MagicMock() pycast_mock.IDLE_APP_ID = pychromecast.IDLE_APP_ID pycast_mock.IGNORE_CEC = [] + pycast_mock.const = pychromecast.const pycast_mock.discovery.CastBrowser = castbrowser_constructor_mock pycast_mock.discovery.CastBrowser.return_value = castbrowser_mock pycast_mock.discovery.AbstractCastListener = ( diff --git a/tests/components/cast/test_media_player.py b/tests/components/cast/test_media_player.py index bbb648a835fa2b92bf35aba9574fd932b8f71ca7..3bb9cbf23169bcc961c52c2ed55d8b445df98e17 100644 --- a/tests/components/cast/test_media_player.py +++ b/tests/components/cast/test_media_player.py @@ -591,6 +591,7 @@ async def test_entity_cast_status(hass: HomeAssistant): ) chromecast, _ = await async_setup_media_player_cast(hass, info) + chromecast.cast_type = pychromecast.const.CAST_TYPE_CHROMECAST cast_status_cb, conn_status_cb, _ = get_status_callbacks(chromecast) connection_status = MagicMock() @@ -660,6 +661,65 @@ async def test_entity_cast_status(hass: HomeAssistant): ) +@pytest.mark.parametrize( + "cast_type,supported_features", + [ + ( + pychromecast.const.CAST_TYPE_AUDIO, + SUPPORT_PAUSE + | SUPPORT_PLAY + | SUPPORT_PLAY_MEDIA + | SUPPORT_STOP + | SUPPORT_TURN_OFF + | SUPPORT_VOLUME_MUTE + | SUPPORT_VOLUME_SET, + ), + ( + pychromecast.const.CAST_TYPE_CHROMECAST, + SUPPORT_PAUSE + | SUPPORT_PLAY + | SUPPORT_PLAY_MEDIA + | SUPPORT_STOP + | SUPPORT_TURN_OFF + | SUPPORT_TURN_ON + | SUPPORT_VOLUME_MUTE + | SUPPORT_VOLUME_SET, + ), + ( + pychromecast.const.CAST_TYPE_GROUP, + SUPPORT_PAUSE + | SUPPORT_PLAY + | SUPPORT_PLAY_MEDIA + | SUPPORT_STOP + | SUPPORT_TURN_OFF + | SUPPORT_VOLUME_MUTE + | SUPPORT_VOLUME_SET, + ), + ], +) +async def test_supported_features(hass: HomeAssistant, cast_type, supported_features): + """Test supported features.""" + entity_id = "media_player.speaker" + + info = get_fake_chromecast_info() + + chromecast, _ = await async_setup_media_player_cast(hass, info) + chromecast.cast_type = cast_type + _, conn_status_cb, _ = get_status_callbacks(chromecast) + + connection_status = MagicMock() + connection_status.status = "CONNECTED" + conn_status_cb(connection_status) + await hass.async_block_till_done() + + state = hass.states.get(entity_id) + assert state is not None + assert state.name == "Speaker" + assert state.state == "off" + + assert state.attributes.get("supported_features") == supported_features + + async def test_entity_play_media(hass: HomeAssistant): """Test playing media.""" entity_id = "media_player.speaker" @@ -872,6 +932,7 @@ async def test_entity_control(hass: HomeAssistant): ) chromecast, _ = await async_setup_media_player_cast(hass, info) + chromecast.cast_type = pychromecast.const.CAST_TYPE_CHROMECAST _, conn_status_cb, media_status_cb = get_status_callbacks(chromecast) connection_status = MagicMock()