Don't allow turning on audio only chromecasts (#59495)
* Don't allow turning on audio only chromecasts * Improve tests * Adjust tests
This commit is contained in:
parent
85786fd987
commit
a29264518c
3 changed files with 69 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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 = (
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue