mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Hide volume control for cast devices with fixed volume (#46328)
This commit is contained in:
parent
ad400d91bc
commit
c66d9ea25c
@ -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"]
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user