Make homekit TV media players aware of STATE_STANDBY (#35282)

This was previously added to non-TV media players.
This commit is contained in:
J. Nick Koston 2020-05-10 17:35:54 -05:00 committed by GitHub
parent 70b29dc823
commit 497c01c651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -93,6 +93,13 @@ MODE_FRIENDLY_NAME = {
FEATURE_TOGGLE_MUTE: "Mute",
}
MEDIA_PLAYER_OFF_STATES = (
STATE_OFF,
STATE_UNKNOWN,
STATE_STANDBY,
"None",
)
@TYPES.register("MediaPlayer")
class MediaPlayer(HomeAccessory):
@ -187,12 +194,7 @@ class MediaPlayer(HomeAccessory):
current_state = new_state.state
if self.chars[FEATURE_ON_OFF]:
hk_state = current_state not in (
STATE_OFF,
STATE_UNKNOWN,
STATE_STANDBY,
"None",
)
hk_state = current_state not in MEDIA_PLAYER_OFF_STATES
_LOGGER.debug(
'%s: Set current state for "on_off" to %s', self.entity_id, hk_state
)
@ -379,7 +381,7 @@ class TelevisionMediaPlayer(HomeAccessory):
# Power state television
hk_state = 0
if current_state not in ("None", STATE_OFF, STATE_UNKNOWN):
if current_state not in MEDIA_PLAYER_OFF_STATES:
hk_state = 1
_LOGGER.debug("%s: Set current active state to %s", self.entity_id, hk_state)
if self.char_active.value != hk_state:

View File

@ -219,6 +219,14 @@ async def test_media_player_television(hass, hk_driver, events, caplog):
await hass.async_block_till_done()
assert acc.char_active.value == 0
hass.states.async_set(entity_id, STATE_ON)
await hass.async_block_till_done()
assert acc.char_active.value == 1
hass.states.async_set(entity_id, STATE_STANDBY)
await hass.async_block_till_done()
assert acc.char_active.value == 0
hass.states.async_set(entity_id, STATE_ON, {ATTR_INPUT_SOURCE: "HDMI 2"})
await hass.async_block_till_done()
assert acc.char_input_source.value == 1