From a110664edb7fd16a84579e2b2a779eacecd21878 Mon Sep 17 00:00:00 2001 From: Stephen Goodall Date: Fri, 18 Feb 2022 11:12:34 +1100 Subject: [PATCH] PR Suggestions (#1) * Reorder _cmd function * Code suggestion change * Code suggestion change * Re-Ordering --- androidtv/basetv/basetv.py | 28 ++++++++++++++-------------- androidtv/basetv/basetv_async.py | 2 +- androidtv/basetv/basetv_sync.py | 2 +- androidtv/constants.py | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/androidtv/basetv/basetv.py b/androidtv/basetv/basetv.py index 2e9a4b1..b47566c 100644 --- a/androidtv/basetv/basetv.py +++ b/androidtv/basetv/basetv.py @@ -116,6 +116,20 @@ def customize_command(self, custom_command, value): elif custom_command in self._custom_commands: del self._custom_commands[custom_command] + 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 + def _cmd_current_app(self): """Get the command used to retrieve the current app for this device. @@ -238,20 +252,6 @@ 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 # diff --git a/androidtv/basetv/basetv_async.py b/androidtv/basetv/basetv_async.py index a565487..1cbac26 100644 --- a/androidtv/basetv/basetv_async.py +++ b/androidtv/basetv/basetv_async.py @@ -242,7 +242,7 @@ async def audio_state(self): Returns ------- str, None - 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 + The audio state, or ``None`` if it could not be determined """ audio_state_response = await self._adb.shell(self._cmd_audio_state()) diff --git a/androidtv/basetv/basetv_sync.py b/androidtv/basetv/basetv_sync.py index ccf947a..e0c81bc 100644 --- a/androidtv/basetv/basetv_sync.py +++ b/androidtv/basetv/basetv_sync.py @@ -242,7 +242,7 @@ def audio_state(self): Returns ------- str, None - 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 + The audio state, or ``None`` if it could not be determined """ audio_state_response = self._adb.shell(self._cmd_audio_state()) diff --git a/androidtv/constants.py b/androidtv/constants.py index 7ca6802..1ecd87a 100644 --- a/androidtv/constants.py +++ b/androidtv/constants.py @@ -35,31 +35,31 @@ class DeviceEnum(IntEnum): INTENT_HOME = "android.intent.category.HOME" # Customizable commands +CUSTOM_AUDIO_STATE = "audio_state" CUSTOM_CURRENT_APP = "current_app" CUSTOM_CURRENT_APP_MEDIA_SESSION_STATE = "current_app_media_session_state" CUSTOM_LAUNCH_APP = "launch_app" CUSTOM_RUNNING_APPS = "running_apps" CUSTOM_TURN_OFF = "turn_off" CUSTOM_TURN_ON = "turn_on" -CUSTOM_AUDIO_STATE = "audio_state" CUSTOMIZABLE_COMMANDS = { + CUSTOM_AUDIO_STATE, 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 HA_CUSTOMIZABLE_COMMANDS = ( + CUSTOM_AUDIO_STATE, CUSTOM_CURRENT_APP_MEDIA_SESSION_STATE, CUSTOM_LAUNCH_APP, CUSTOM_RUNNING_APPS, CUSTOM_TURN_OFF, CUSTOM_TURN_ON, - CUSTOM_AUDIO_STATE, ) # echo '1' if the previous shell command was successful