Skip to content

Commit 91b516d

Browse files
elupusjoostlekemontnemery
authored
Respect hdmi isActiveInput for chromecast devices (home-assistant#149150)
Co-authored-by: Joost Lekkerkerker <[email protected]> Co-authored-by: Erik Montnemery <[email protected]>
1 parent 25a9948 commit 91b516d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

homeassistant/components/cast/media_player.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,13 +816,20 @@ def state(self) -> MediaPlayerState | None:
816816
return MediaPlayerState.PAUSED
817817
if media_status.player_is_idle:
818818
return MediaPlayerState.IDLE
819-
if self.app_id is not None and self.app_id != pychromecast.IDLE_APP_ID:
820-
if self.app_id in APP_IDS_UNRELIABLE_MEDIA_INFO:
821-
# Some apps don't report media status, show the player as playing
822-
return MediaPlayerState.PLAYING
823-
return MediaPlayerState.IDLE
819+
824820
if self._chromecast is not None and self._chromecast.is_idle:
821+
# If library consider us idle, that is our off state
822+
# it takes HDMI status into account for cast devices.
825823
return MediaPlayerState.OFF
824+
825+
if self.app_id in APP_IDS_UNRELIABLE_MEDIA_INFO:
826+
# Some apps don't report media status, show the player as playing
827+
return MediaPlayerState.PLAYING
828+
829+
if self.app_id is not None:
830+
# We have an active app
831+
return MediaPlayerState.IDLE
832+
826833
return None
827834

828835
@property

tests/components/cast/test_media_player.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def get_fake_chromecast(info: ChromecastInfo):
6868
mock = MagicMock(uuid=info.uuid)
6969
mock.app_id = None
7070
mock.media_controller.status = None
71+
mock.is_idle = True
7172
return mock
7273

7374

@@ -887,6 +888,7 @@ async def test_entity_cast_status(
887888
assert not state.attributes.get("is_volume_muted")
888889

889890
chromecast.app_id = "1234"
891+
chromecast.is_idle = False
890892
cast_status = MagicMock()
891893
cast_status.volume_level = 0.5
892894
cast_status.volume_muted = False
@@ -1599,6 +1601,7 @@ async def test_entity_media_states(
15991601

16001602
# App id updated, but no media status
16011603
chromecast.app_id = app_id
1604+
chromecast.is_idle = False
16021605
cast_status = MagicMock()
16031606
cast_status_cb(cast_status)
16041607
await hass.async_block_till_done()
@@ -1641,13 +1644,15 @@ async def test_entity_media_states(
16411644

16421645
# App no longer running
16431646
chromecast.app_id = pychromecast.IDLE_APP_ID
1647+
chromecast.is_idle = True
16441648
cast_status = MagicMock()
16451649
cast_status_cb(cast_status)
16461650
await hass.async_block_till_done()
16471651
state = hass.states.get(entity_id)
16481652
assert state.state == "off"
16491653

16501654
# No cast status
1655+
chromecast.app_id = None
16511656
chromecast.is_idle = False
16521657
cast_status_cb(None)
16531658
await hass.async_block_till_done()
@@ -1722,6 +1727,7 @@ async def test_entity_media_states_lovelace_app(
17221727
state = hass.states.get(entity_id)
17231728
assert state.state == "off"
17241729

1730+
chromecast.app_id = None
17251731
chromecast.is_idle = False
17261732
media_status_cb(media_status)
17271733
await hass.async_block_till_done()

0 commit comments

Comments
 (0)