Improve handling of audio groups (#22396)
* Improve handling of audio groups * Review comments * Fix tests * Add tests * Review comment * Bump pychromecast
This commit is contained in:
1 parent
64306922b1
commit
2e375aa802
4 files changed
+461
-33
No files matched your search
@@ -24,12 +24,14 @@ def cast_mock():
|
||||
"""Mock pychromecast."""
|
||||
with patch.dict('sys.modules', {
|
||||
'pychromecast': MagicMock(),
|
||||
'pychromecast.controllers.multizone': MagicMock(),
|
||||
}):
|
||||
yield
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
FakeUUID = UUID('57355bce-9364-4aa6-ac1e-eb849dccf9e2')
|
||||
FakeGroupUUID = UUID('57355bce-9364-4aa6-ac1e-eb849dccf9e3')
|
||||
|
||||
|
||||
def get_fake_chromecast(info: ChromecastInfo):
|
||||
@@ -300,6 +302,101 @@ async def test_entity_media_states(hass: HomeAssistantType):
|
||||
assert state.state == 'unknown'
|
||||
|
||||
|
||||
async def test_group_media_states(hass: HomeAssistantType):
|
||||
"""Test media states are read from group if entity has no state."""
|
||||
info = get_fake_chromecast_info()
|
||||
full_info = attr.evolve(info, model_name='google home',
|
||||
friendly_name='Speaker', uuid=FakeUUID)
|
||||
|
||||
with patch('pychromecast.dial.get_device_status',
|
||||
return_value=full_info):
|
||||
chromecast, entity = await async_setup_media_player_cast(hass, info)
|
||||
|
||||
entity._available = True
|
||||
entity.schedule_update_ha_state()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('media_player.speaker')
|
||||
assert state is not None
|
||||
assert state.name == 'Speaker'
|
||||
assert state.state == 'unknown'
|
||||
assert entity.unique_id == full_info.uuid
|
||||
|
||||
group_media_status = MagicMock(images=None)
|
||||
player_media_status = MagicMock(images=None)
|
||||
|
||||
# Player has no state, group is playing -> Should report 'playing'
|
||||
group_media_status.player_is_playing = True
|
||||
entity.multizone_new_media_status(str(FakeGroupUUID), group_media_status)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('media_player.speaker')
|
||||
assert state.state == 'playing'
|
||||
|
||||
# Player is paused, group is playing -> Should report 'paused'
|
||||
player_media_status.player_is_playing = False
|
||||
player_media_status.player_is_paused = True
|
||||
entity.new_media_status(player_media_status)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('media_player.speaker')
|
||||
assert state.state == 'paused'
|
||||
|
||||
# Player is in unknown state, group is playing -> Should report 'playing'
|
||||
player_media_status.player_state = "UNKNOWN"
|
||||
entity.new_media_status(player_media_status)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('media_player.speaker')
|
||||
assert state.state == 'playing'
|
||||
|
||||
|
||||
async def test_dynamic_group_media_states(hass: HomeAssistantType):
|
||||
"""Test media states are read from group if entity has no state."""
|
||||
info = get_fake_chromecast_info()
|
||||
full_info = attr.evolve(info, model_name='google home',
|
||||
friendly_name='Speaker', uuid=FakeUUID)
|
||||
|
||||
with patch('pychromecast.dial.get_device_status',
|
||||
return_value=full_info):
|
||||
chromecast, entity = await async_setup_media_player_cast(hass, info)
|
||||
|
||||
entity._available = True
|
||||
entity.schedule_update_ha_state()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('media_player.speaker')
|
||||
assert state is not None
|
||||
assert state.name == 'Speaker'
|
||||
assert state.state == 'unknown'
|
||||
assert entity.unique_id == full_info.uuid
|
||||
|
||||
group_media_status = MagicMock(images=None)
|
||||
player_media_status = MagicMock(images=None)
|
||||
|
||||
# Player has no state, dynamic group is playing -> Should report 'playing'
|
||||
group_media_status.player_is_playing = True
|
||||
entity.new_dynamic_group_media_status(group_media_status)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('media_player.speaker')
|
||||
assert state.state == 'playing'
|
||||
|
||||
# Player is paused, dynamic group is playing -> Should report 'paused'
|
||||
player_media_status.player_is_playing = False
|
||||
player_media_status.player_is_paused = True
|
||||
entity.new_media_status(player_media_status)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('media_player.speaker')
|
||||
assert state.state == 'paused'
|
||||
|
||||
# Player is in unknown state, dynamic group is playing -> Should report
|
||||
# 'playing'
|
||||
player_media_status.player_state = "UNKNOWN"
|
||||
entity.new_media_status(player_media_status)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('media_player.speaker')
|
||||
assert state.state == 'playing'
|
||||
|
||||
|
||||
async def test_disconnect_on_stop(hass: HomeAssistantType):
|
||||
"""Test cast device disconnects socket on stop."""
|
||||
info = get_fake_chromecast_info()
|
||||
|
||||
Reference in new issue
Block a user