Skip to content

Commit

Permalink
Merge 37746de into 813cfbf
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGoodall committed Feb 15, 2022
2 parents 813cfbf + 37746de commit d4d8d8b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
14 changes: 14 additions & 0 deletions androidtv/basetv/basetv.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ def _cmd_turn_on(self):

return constants.CMD_TURN_ON_ANDROIDTV

def _cmd_audio_state(self):
"""Get the command used to retrieve the current audio state for this device.
Returns
-------
str
The device-specific ADB shell command used to determine the current audio state
"""
if constants.CUSTOM_AUDIO_STATE in self._custom_commands:
return self._custom_commands[constants.CUSTOM_AUDIO_STATE]

return constants.CMD_AUDIO_STATE

# ======================================================================= #
# #
# ADB methods #
Expand Down
2 changes: 1 addition & 1 deletion androidtv/basetv/basetv_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ async def audio_state(self):
The audio state, as determined from the ADB shell command :py:const:`androidtv.constants.CMD_AUDIO_STATE`, or ``None`` if it could not be determined
"""
audio_state_response = await self._adb.shell(constants.CMD_AUDIO_STATE)
audio_state_response = await self._adb.shell(self._cmd_audio_state())
return self._audio_state(audio_state_response)

async def awake(self):
Expand Down
2 changes: 1 addition & 1 deletion androidtv/basetv/basetv_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def audio_state(self):
The audio state, as determined from the ADB shell command :py:const:`androidtv.constants.CMD_AUDIO_STATE`, or ``None`` if it could not be determined
"""
audio_state_response = self._adb.shell(constants.CMD_AUDIO_STATE)
audio_state_response = self._adb.shell(self._cmd_audio_state())
return self._audio_state(audio_state_response)

def awake(self):
Expand Down
3 changes: 3 additions & 0 deletions androidtv/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ class DeviceEnum(IntEnum):
CUSTOM_RUNNING_APPS = "running_apps"
CUSTOM_TURN_OFF = "turn_off"
CUSTOM_TURN_ON = "turn_on"
CUSTOM_AUDIO_STATE = "audio_state"
CUSTOMIZABLE_COMMANDS = {
CUSTOM_CURRENT_APP,
CUSTOM_CURRENT_APP_MEDIA_SESSION_STATE,
CUSTOM_LAUNCH_APP,
CUSTOM_RUNNING_APPS,
CUSTOM_TURN_OFF,
CUSTOM_TURN_ON,
CUSTOM_AUDIO_STATE,
}

#: The subset of `CUSTOMIZABLE_COMMANDS` that is potentially used in the ``update()`` method
Expand All @@ -57,6 +59,7 @@ class DeviceEnum(IntEnum):
CUSTOM_RUNNING_APPS,
CUSTOM_TURN_OFF,
CUSTOM_TURN_ON,
CUSTOM_AUDIO_STATE,
)

# echo '1' if the previous shell command was successful
Expand Down
5 changes: 5 additions & 0 deletions tests/test_androidtv_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ def test_customize_command(self):
self.atv.turn_on()
patched.assert_called_with("5")

self.atv.customize_command(constants.CUSTOM_AUDIO_STATE, "6")
with patch.object(self.atv._adb, "shell") as patched:
self.atv.audio_state()
patched.assert_called_with("6")

# Delete a custom command
self.atv.customize_command(constants.CUSTOM_TURN_ON, None)
with patch.object(self.atv._adb, "shell") as patched:
Expand Down

0 comments on commit d4d8d8b

Please sign in to comment.