Skip to content

Commit

Permalink
Add a check that 'ANDROID_TV', 'BASE_TV', and 'FIRE_TV' do not appear…
Browse files Browse the repository at this point in the history
… in the code
  • Loading branch information
JeffLIrion committed Jan 20, 2022
1 parent 3d3f004 commit d105292
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion androidtv/androidtv/base_androidtv.py
Expand Up @@ -33,7 +33,7 @@ class BaseAndroidTV(BaseTV): # pylint: disable=too-few-public-methods
"""

DEVICE_CLASS = "androidtv"
DEVICE_ENUM = constants.DeviceEnum.ANDROID_TV
DEVICE_ENUM = constants.DeviceEnum.ANDROIDTV

def __init__(self, host, port=5555, adbkey="", adb_server_ip="", adb_server_port=5037, state_detection_rules=None):
BaseTV.__init__(self, None, host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules)
Expand Down
14 changes: 7 additions & 7 deletions androidtv/basetv/basetv.py
Expand Up @@ -66,7 +66,7 @@ class BaseTV(object): # pylint: disable=too-few-public-methods
"""

DEVICE_ENUM = constants.DeviceEnum.BASE_TV
DEVICE_ENUM = constants.DeviceEnum.BASETV

def __init__(
self, adb, host, port=5555, adbkey="", adb_server_ip="", adb_server_port=5037, state_detection_rules=None
Expand Down Expand Up @@ -107,7 +107,7 @@ def _cmd_current_app(self):
"""
# Is this a Google Chromecast Android TV?
if (
self.DEVICE_ENUM == constants.DeviceEnum.ANDROID_TV
self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV
and "Google" in self.device_properties.get("manufacturer", "")
and "Chromecast" in self.device_properties.get("model", "")
):
Expand All @@ -126,7 +126,7 @@ def _cmd_current_app_media_session_state(self):
"""
# Is this a Google Chromecast Android TV?
if (
self.DEVICE_ENUM == constants.DeviceEnum.ANDROID_TV
self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV
and "Google" in self.device_properties.get("manufacturer", "")
and "Chromecast" in self.device_properties.get("model", "")
):
Expand All @@ -150,7 +150,7 @@ def _cmd_launch_app(self, app):
"""
# Is this a Google Chromecast Android TV?
if (
self.DEVICE_ENUM == constants.DeviceEnum.ANDROID_TV
self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV
and "Google" in self.device_properties.get("manufacturer", "")
and "Chromecast" in self.device_properties.get("model", "")
):
Expand All @@ -167,7 +167,7 @@ def _cmd_running_apps(self):
The device-specific ADB shell command used to determine the running apps
"""
if self.DEVICE_ENUM == constants.DeviceEnum.FIRE_TV:
if self.DEVICE_ENUM == constants.DeviceEnum.FIRETV:
return constants.CMD_RUNNING_APPS_FIRETV

return constants.CMD_RUNNING_APPS_ANDROIDTV
Expand All @@ -181,7 +181,7 @@ def _cmd_turn_off(self):
The device-specific ADB shell command used to turn off the device
"""
if self.DEVICE_ENUM == constants.DeviceEnum.FIRE_TV:
if self.DEVICE_ENUM == constants.DeviceEnum.FIRETV:
return constants.CMD_TURN_OFF_FIRETV

return constants.CMD_TURN_OFF_ANDROIDTV
Expand All @@ -195,7 +195,7 @@ def _cmd_turn_on(self):
The device-specific ADB shell command used to turn on the device
"""
if self.DEVICE_ENUM == constants.DeviceEnum.FIRE_TV:
if self.DEVICE_ENUM == constants.DeviceEnum.FIRETV:
return constants.CMD_TURN_ON_FIRETV

return constants.CMD_TURN_ON_ANDROIDTV
Expand Down
6 changes: 3 additions & 3 deletions androidtv/constants.py
Expand Up @@ -25,9 +25,9 @@ def unique(cls):
class DeviceEnum(IntEnum):
"""An enum for the various device types."""

BASE_TV = 0
ANDROID_TV = 1
FIRE_TV = 2
BASETV = 0
ANDROIDTV = 1
FIRETV = 2


# Intents
Expand Down
2 changes: 1 addition & 1 deletion androidtv/firetv/base_firetv.py
Expand Up @@ -33,7 +33,7 @@ class BaseFireTV(BaseTV): # pylint: disable=too-few-public-methods
"""

DEVICE_CLASS = "firetv"
DEVICE_ENUM = constants.DeviceEnum.FIRE_TV
DEVICE_ENUM = constants.DeviceEnum.FIRETV

def __init__(self, host, port=5555, adbkey="", adb_server_ip="", adb_server_port=5037, state_detection_rules=None):
BaseTV.__init__(self, None, host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_constants.py
@@ -1,5 +1,7 @@
import inspect
import os
import shlex
import subprocess
import sys
import unittest

Expand Down Expand Up @@ -169,6 +171,13 @@ def test_constants(self):
# CMD_WAKE_LOCK_SIZE
self.assertEqual(constants.CMD_WAKE_LOCK_SIZE, r"dumpsys power | grep Locks | grep 'size='")

def test_no_underscores(self):
"""Test that 'ANDROID_TV', 'BASE_TV', and 'FIRE_TV' do not appear in the code base."""
cwd = os.path.join(os.path.dirname(__file__), "..")
for underscore_name in ["ANDROID_TV", "BASE_TV", "FIRE_TV"]:
with subprocess.Popen(shlex.split("git grep -l {} -- androidtv/".format(underscore_name)), cwd=cwd) as p:
self.assertEqual(p.wait(), 1)

def test_current_app_extraction_atv_launcher(self):
dumpsys_output = """
mCurrentFocus=Window{e74bb23 u0 com.google.android.tvlauncher/com.google.android.tvlauncher.MainActivity}
Expand Down

0 comments on commit d105292

Please sign in to comment.