Skip to content

Commit 428dc05

Browse files
committed
fix: Power on/off command handling based on device state
The Android TV commands only support a power toggle command. Based on the Home Assistant integration: https://github.com/home-assistant/core/blob/2023.11.0/homeassistant/components/androidtv_remote/media_player.py#L115-L123
1 parent 2f49fa1 commit 428dc05

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

intg-androidtv/driver.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def on_exit_standby():
7373
"""
7474
Exit standby notification.
7575
76-
Connect all Denon AVR instances.
76+
Connect all Android TV instances.
7777
"""
7878
_LOG.debug("Exit standby event: connecting device(s)")
7979
for configured in _configured_android_tvs.values():
@@ -146,8 +146,6 @@ async def media_player_cmd_handler(
146146

147147
android_tv = _configured_android_tvs[atv_id]
148148

149-
# TODO might require special handling on the current device state to avoid toggling power state
150-
# https://github.com/home-assistant/core/blob/2023.11.0/homeassistant/components/androidtv_remote/media_player.py#L115-L123
151149
if cmd_id == media_player.Commands.ON:
152150
return await android_tv.turn_on()
153151
if cmd_id == media_player.Commands.OFF:

intg-androidtv/profiles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
MEDIA_PLAYER_COMMANDS = {
2424
media_player.Commands.ON.value: "POWER",
2525
media_player.Commands.OFF.value: "POWER",
26+
media_player.Commands.TOGGLE.value: "POWER",
2627
media_player.Commands.PLAY_PAUSE.value: "MEDIA_PLAY_PAUSE",
2728
media_player.Commands.STOP.value: "MEDIA_STOP",
2829
media_player.Commands.PREVIOUS.value: "MEDIA_PREVIOUS",

intg-androidtv/tv.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,24 @@ async def send_media_player_command(self, cmd_id: str) -> ucapi.StatusCodes:
439439

440440
async def turn_on(self) -> ucapi.StatusCodes:
441441
"""
442-
Send power command to AndroidTV device.
442+
Send power command to AndroidTV device if device is in off-state.
443443
444-
Note: there's no dedicated power-on command!
444+
Note: there's no dedicated power-on command! Power handling based on HA integration:
445+
https://github.com/home-assistant/core/blob/2023.11.0/homeassistant/components/androidtv_remote/media_player.py#L115-L123
445446
"""
446-
return await self._send_command("POWER")
447+
if not self.is_on:
448+
return await self._send_command("POWER")
449+
return ucapi.StatusCodes.OK
447450

448451
async def turn_off(self) -> ucapi.StatusCodes:
449452
"""
450-
Send power command to AndroidTV device.
453+
Send power command to AndroidTV device if device is in off-state.
451454
452455
Note: there's no dedicated power-off command!
453456
"""
454-
return await self._send_command("POWER")
457+
if self.is_on:
458+
return await self._send_command("POWER")
459+
return ucapi.StatusCodes.OK
455460

456461
async def select_source(self, source: str) -> ucapi.StatusCodes:
457462
"""

0 commit comments

Comments
 (0)