Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Mar 26, 2022
1 parent b7d5bbc commit 902e2fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions androidtv/basetv/basetv.py
Expand Up @@ -128,7 +128,7 @@ def _cmd_audio_state(self):
if constants.CUSTOM_AUDIO_STATE in self._custom_commands:
return self._custom_commands[constants.CUSTOM_AUDIO_STATE]

# Is this an Android 11 device??
# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_AUDIO_STATE11
return constants.CMD_AUDIO_STATE
Expand All @@ -152,7 +152,7 @@ def _cmd_current_app(self):
and "Chromecast" in self.device_properties.get("model", "")
):
return constants.CMD_CURRENT_APP_GOOGLE_TV
# Is this an Android 11 device??
# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_CURRENT_APP11

Expand All @@ -177,7 +177,7 @@ def _cmd_current_app_media_session_state(self):
and "Chromecast" in self.device_properties.get("model", "")
):
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE_GOOGLE_TV
# Is this an Android 11 device??
# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE11

Expand All @@ -195,7 +195,7 @@ def _cmd_hdmi_input(self):
if constants.CUSTOM_HDMI_INPUT in self._custom_commands:
return self._custom_commands[constants.CUSTOM_HDMI_INPUT]

# Is this an Android 11 device??
# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_HDMI_INPUT11

Expand Down Expand Up @@ -229,7 +229,7 @@ def _cmd_launch_app(self, app):
if self.DEVICE_ENUM == constants.DeviceEnum.FIRETV:
return constants.CMD_LAUNCH_APP_FIRETV.format(app)

# Is this an Android 11 device??
# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_LAUNCH_APP11.format(app)

Expand Down
15 changes: 8 additions & 7 deletions androidtv/constants.py
Expand Up @@ -75,7 +75,7 @@ class DeviceEnum(IntEnum):
#: Get the audio state
CMD_AUDIO_STATE = r"dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\c' || echo '0\c')"

#: Get the audio state for an Android 11 Device
#: Get the audio state for an Android 11 device
CMD_AUDIO_STATE11 = (
"CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*state:.*$/h; ${x;p;}') && "
+ r"echo $CURRENT_AUDIO_STATE | grep -q paused && echo -e '1\c' || { echo $CURRENT_AUDIO_STATE | grep -q started && echo '2\c' || echo '0\c' ; }"
Expand All @@ -87,14 +87,14 @@ class DeviceEnum(IntEnum):
#: Parse current application identifier from dumpsys output and assign it to ``CURRENT_APP`` variable (assumes dumpsys output is momentarily set to ``CURRENT_APP`` variable)
CMD_PARSE_CURRENT_APP = "CURRENT_APP=${CURRENT_APP#*ActivityRecord{* * } && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP%\\}*}"

#: Parse current application for an Android 11 Device
#: Parse current application for an Android 11 device
CMD_PARSE_CURRENT_APP11 = "CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP##* }"

#: Assign focused application identifier to ``CURRENT_APP`` variable
CMD_DEFINE_CURRENT_APP_VARIABLE = (
"CURRENT_APP=$(dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp') && " + CMD_PARSE_CURRENT_APP
)
#: Assign focused application identifier to ``CURRENT_APP`` variable for an Android 11 Device
#: Assign focused application identifier to ``CURRENT_APP`` variable for an Android 11 device
CMD_DEFINE_CURRENT_APP_VARIABLE11 = (
"CURRENT_APP=$(dumpsys window windows | grep 'Window #1') && " + CMD_PARSE_CURRENT_APP11
)
Expand All @@ -103,7 +103,7 @@ class DeviceEnum(IntEnum):
#: Output identifier for current/focused application
CMD_CURRENT_APP = CMD_DEFINE_CURRENT_APP_VARIABLE + " && echo $CURRENT_APP"

#: Output identifier for current/focused application for an Android 11 Device
#: Output identifier for current/focused application for an Android 11 device
CMD_CURRENT_APP11 = CMD_DEFINE_CURRENT_APP_VARIABLE11 + " && echo $CURRENT_APP"

#: Assign focused application identifier to ``CURRENT_APP`` variable (for a Google TV device)
Expand All @@ -118,7 +118,8 @@ class DeviceEnum(IntEnum):
CMD_HDMI_INPUT = (
"dumpsys activity starter | grep -E -o '(ExternalTv|HDMI)InputService/HW[0-9]' -m 1 | grep -o 'HW[0-9]'"
)
#: Get the HDMI input for an Android 11 Device

#: Get the HDMI input for an Android 11 device
CMD_HDMI_INPUT11 = (
"(HDMI=$(dumpsys tv_input | grep 'ResourceClientProfile {.*}' | grep -o -E '(hdmi_port=[0-9]|TV)') && { echo ${HDMI/hdmi_port=/HW} | cut -d' ' -f1 ; }) || "
+ CMD_HDMI_INPUT
Expand All @@ -139,7 +140,7 @@ class DeviceEnum(IntEnum):
CMD_DEFINE_CURRENT_APP_VARIABLE.replace("{", "{{").replace("}", "}}") + " && " + CMD_LAUNCH_APP_CONDITION
)

#: Launch an app if it is not already the current app on an Android 11 Device
#: Launch an app if it is not already the current app on an Android 11 device
CMD_LAUNCH_APP11 = (
CMD_DEFINE_CURRENT_APP_VARIABLE11.replace("{", "{{").replace("}", "}}") + " && " + CMD_LAUNCH_APP_CONDITION
)
Expand All @@ -160,7 +161,7 @@ class DeviceEnum(IntEnum):
#: Determine the current app and get the state from ``dumpsys media_session``
CMD_CURRENT_APP_MEDIA_SESSION_STATE = CMD_CURRENT_APP + " && " + CMD_MEDIA_SESSION_STATE

#: Determine the current app and get the state from ``dumpsys media_session`` for an Android 11 Device
#: Determine the current app and get the state from ``dumpsys media_session`` for an Android 11 device
CMD_CURRENT_APP_MEDIA_SESSION_STATE11 = CMD_CURRENT_APP11 + " && " + CMD_MEDIA_SESSION_STATE

#: Determine the current app and get the state from ``dumpsys media_session`` for a Google TV device
Expand Down

0 comments on commit 902e2fb

Please sign in to comment.