diff --git a/homeassistant/components/cast/manifest.json b/homeassistant/components/cast/manifest.json index 88dabc8d04d..5963e93cf8c 100644 --- a/homeassistant/components/cast/manifest.json +++ b/homeassistant/components/cast/manifest.json @@ -3,7 +3,7 @@ "name": "Google Cast", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/cast", - "requirements": ["pychromecast==8.0.0"], + "requirements": ["pychromecast==8.1.0"], "after_dependencies": ["cloud", "http", "media_source", "plex", "tts", "zeroconf"], "zeroconf": ["_googlecast._tcp.local."], "codeowners": ["@emontnemery"] diff --git a/homeassistant/components/cast/media_player.py b/homeassistant/components/cast/media_player.py index 6bedae1cac5..981d67f0caa 100644 --- a/homeassistant/components/cast/media_player.py +++ b/homeassistant/components/cast/media_player.py @@ -10,6 +10,7 @@ import pychromecast from pychromecast.controllers.homeassistant import HomeAssistantController from pychromecast.controllers.multizone import MultizoneManager from pychromecast.controllers.plex import PlexController +from pychromecast.controllers.receiver import VOLUME_CONTROL_TYPE_FIXED from pychromecast.quick_play import quick_play from pychromecast.socket_client import ( CONNECTION_STATUS_CONNECTED, @@ -82,8 +83,6 @@ SUPPORT_CAST = ( | SUPPORT_STOP | SUPPORT_TURN_OFF | SUPPORT_TURN_ON - | SUPPORT_VOLUME_MUTE - | SUPPORT_VOLUME_SET ) @@ -743,6 +742,10 @@ class CastDevice(MediaPlayerEntity): support = SUPPORT_CAST media_status = self._media_status()[0] + if self.cast_status: + if self.cast_status.volume_control_type != VOLUME_CONTROL_TYPE_FIXED: + support |= SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET + if media_status: if media_status.supports_queue_next: support |= SUPPORT_PREVIOUS_TRACK diff --git a/requirements_all.txt b/requirements_all.txt index ca536e1cc8b..9f2aef26012 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1310,7 +1310,7 @@ pycfdns==1.2.1 pychannels==1.0.0 # homeassistant.components.cast -pychromecast==8.0.0 +pychromecast==8.1.0 # homeassistant.components.pocketcasts pycketcasts==1.0.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 7f1f5df2d81..143ec43a5d4 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -681,7 +681,7 @@ pybotvac==0.0.20 pycfdns==1.2.1 # homeassistant.components.cast -pychromecast==8.0.0 +pychromecast==8.1.0 # homeassistant.components.comfoconnect pycomfoconnect==0.4 diff --git a/tests/components/cast/test_media_player.py b/tests/components/cast/test_media_player.py index 050d6a6932d..be24afcb538 100644 --- a/tests/components/cast/test_media_player.py +++ b/tests/components/cast/test_media_player.py @@ -11,6 +11,19 @@ import pytest from homeassistant.components import tts from homeassistant.components.cast import media_player as cast from homeassistant.components.cast.media_player import ChromecastInfo +from homeassistant.components.media_player.const import ( + SUPPORT_NEXT_TRACK, + SUPPORT_PAUSE, + SUPPORT_PLAY, + SUPPORT_PLAY_MEDIA, + SUPPORT_PREVIOUS_TRACK, + SUPPORT_SEEK, + SUPPORT_STOP, + SUPPORT_TURN_OFF, + SUPPORT_TURN_ON, + SUPPORT_VOLUME_MUTE, + SUPPORT_VOLUME_SET, +) from homeassistant.config import async_process_ha_core_config from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.exceptions import PlatformNotReady @@ -662,6 +675,17 @@ async def test_entity_cast_status(hass: HomeAssistantType): assert state.state == "unknown" assert entity_id == reg.async_get_entity_id("media_player", "cast", full_info.uuid) + assert state.attributes.get("supported_features") == ( + SUPPORT_PAUSE + | SUPPORT_PLAY + | SUPPORT_PLAY_MEDIA + | SUPPORT_STOP + | SUPPORT_TURN_OFF + | SUPPORT_TURN_ON + | SUPPORT_VOLUME_MUTE + | SUPPORT_VOLUME_SET + ) + cast_status = MagicMock() cast_status.volume_level = 0.5 cast_status.volume_muted = False @@ -680,6 +704,21 @@ async def test_entity_cast_status(hass: HomeAssistantType): assert state.attributes.get("volume_level") == 0.2 assert state.attributes.get("is_volume_muted") + # Disable support for volume control + cast_status = MagicMock() + cast_status.volume_control_type = "fixed" + cast_status_cb(cast_status) + await hass.async_block_till_done() + state = hass.states.get(entity_id) + assert state.attributes.get("supported_features") == ( + SUPPORT_PAUSE + | SUPPORT_PLAY + | SUPPORT_PLAY_MEDIA + | SUPPORT_STOP + | SUPPORT_TURN_OFF + | SUPPORT_TURN_ON + ) + async def test_entity_play_media(hass: HomeAssistantType): """Test playing media.""" @@ -894,6 +933,17 @@ async def test_entity_control(hass: HomeAssistantType): assert state.state == "unknown" assert entity_id == reg.async_get_entity_id("media_player", "cast", full_info.uuid) + assert state.attributes.get("supported_features") == ( + SUPPORT_PAUSE + | SUPPORT_PLAY + | SUPPORT_PLAY_MEDIA + | SUPPORT_STOP + | SUPPORT_TURN_OFF + | SUPPORT_TURN_ON + | SUPPORT_VOLUME_MUTE + | SUPPORT_VOLUME_SET + ) + # Turn on await common.async_turn_on(hass, entity_id) chromecast.play_media.assert_called_once_with( @@ -940,6 +990,21 @@ async def test_entity_control(hass: HomeAssistantType): media_status_cb(media_status) await hass.async_block_till_done() + state = hass.states.get(entity_id) + assert state.attributes.get("supported_features") == ( + SUPPORT_PAUSE + | SUPPORT_PLAY + | SUPPORT_PLAY_MEDIA + | SUPPORT_STOP + | SUPPORT_TURN_OFF + | SUPPORT_TURN_ON + | SUPPORT_PREVIOUS_TRACK + | SUPPORT_NEXT_TRACK + | SUPPORT_SEEK + | SUPPORT_VOLUME_MUTE + | SUPPORT_VOLUME_SET + ) + # Media previous await common.async_media_previous_track(hass, entity_id) chromecast.media_controller.queue_prev.assert_called_once_with()