Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Jan 19, 2022
1 parent bae1161 commit 9ecd68b
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 43 deletions.
10 changes: 2 additions & 8 deletions androidtv/__init__.py
Expand Up @@ -83,16 +83,10 @@ def setup(

# Fire TV
if aftv.device_properties.get("manufacturer") == "Amazon":
aftv = FireTVSync.from_base(aftv)
return FireTVSync.from_base(aftv)

# Android TV
else:
aftv = AndroidTVSync.from_base(aftv)

# Fill in commands that are specific to the device
aftv._fill_in_commands() # pylint: disable=protected-access

return aftv
return AndroidTVSync.from_base(aftv)


def ha_state_detection_rules_validator(exc):
Expand Down
3 changes: 0 additions & 3 deletions androidtv/androidtv/androidtv_async.py
Expand Up @@ -47,9 +47,6 @@ def __init__(
): # pylint: disable=super-init-not-called
BaseTVAsync.__init__(self, host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)

# fill in commands that can vary based on the device
BaseAndroidTV._fill_in_commands(self)

@classmethod
def from_base(cls, base_tv):
"""Construct an `AndroidTVAsync` object from a `BaseTVAsync` object.
Expand Down
3 changes: 0 additions & 3 deletions androidtv/androidtv/androidtv_sync.py
Expand Up @@ -47,9 +47,6 @@ def __init__(
): # pylint: disable=super-init-not-called
BaseTVSync.__init__(self, host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)

# fill in commands that can vary based on the device
BaseAndroidTV._fill_in_commands(self)

@classmethod
def from_base(cls, base_tv):
"""Construct an `AndroidTVSync` object from a `BaseTVSync` object.
Expand Down
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.BASE_TV
DEVICE_ENUM = constants.DeviceEnum.ANDROID_TV

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
13 changes: 2 additions & 11 deletions androidtv/basetv/basetv.py
Expand Up @@ -97,13 +97,6 @@ def __init__(
# the max volume level (determined when first getting the volume level)
self.max_volume = None

def _fill_in_commands(self):
"""Fill in commands that are specific to the device.
This is implemented in the `BaseAndroidTV` and `BaseFireTV` classes.
"""

# ======================================================================= #
# #
# Device-specific ADB commands #
Expand All @@ -120,7 +113,7 @@ def _cmd_current_app(self):
"""
# Is this a Google Chromecast Android TV?
# assert self.DEVICE_ENUM == constants.DeviceEnum.ANDROID_TV
assert self.DEVICE_ENUM == constants.DeviceEnum.BASE_TV
# assert self.DEVICE_ENUM == constants.DeviceEnum.BASE_TV
# assert "Google" in self.device_properties.get("manufacturer", "")
# assert "Chromecast" in self.device_properties.get("model", "")
if (
Expand Down Expand Up @@ -184,7 +177,7 @@ def _cmd_running_apps(self):
The device-specific ADB shell command used to determine the running apps
"""
assert self.DEVICE_ENUM == constants.DeviceEnum.BASE_TV
# assert self.DEVICE_ENUM == constants.DeviceEnum.BASE_TV
if self.DEVICE_ENUM == constants.DeviceEnum.FIRE_TV:
return constants.CMD_RUNNING_APPS_FIRETV

Expand Down Expand Up @@ -279,8 +272,6 @@ def _parse_device_properties(self, properties):
"ethmac": ethmac,
}

self._fill_in_commands()

# ======================================================================= #
# #
# Custom state detection #
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.BASE_TV
DEVICE_ENUM = constants.DeviceEnum.FIRE_TV

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
3 changes: 0 additions & 3 deletions androidtv/firetv/firetv_async.py
Expand Up @@ -47,9 +47,6 @@ def __init__(
): # pylint: disable=super-init-not-called
BaseTVAsync.__init__(self, host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)

# fill in commands that can vary based on the device
BaseFireTV._fill_in_commands(self)

@classmethod
def from_base(cls, base_tv):
"""Construct a `FireTVAsync` object from a `BaseTVAsync` object.
Expand Down
3 changes: 0 additions & 3 deletions androidtv/firetv/firetv_sync.py
Expand Up @@ -47,9 +47,6 @@ def __init__(
): # pylint: disable=super-init-not-called
BaseTVSync.__init__(self, host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)

# fill in commands that can vary based on the device
BaseFireTV._fill_in_commands(self)

@classmethod
def from_base(cls, base_tv):
"""Construct a `FireTVSync` object from a `BaseTVSync` object.
Expand Down
10 changes: 2 additions & 8 deletions androidtv/setup_async.py
Expand Up @@ -79,13 +79,7 @@ async def setup(

# Fire TV
if aftv.device_properties.get("manufacturer") == "Amazon":
aftv = FireTVAsync.from_base(aftv)
return FireTVAsync.from_base(aftv)

# Android TV
else:
aftv = AndroidTVAsync.from_base(aftv)

# Fill in commands that are specific to the device
aftv._fill_in_commands() # pylint: disable=protected-access

return aftv
return AndroidTVAsync.from_base(aftv)
11 changes: 9 additions & 2 deletions tests/test_basetv_sync.py
Expand Up @@ -461,7 +461,6 @@ def test_get_device_properties(self):
with patchers.patch_shell("")[self.PATCH_KEY]:
device_properties = self.btv.get_device_properties()
self.assertDictEqual({}, device_properties)
return # FIX

with patchers.patch_shell(DEVICE_PROPERTIES_GOOGLE_TV)[self.PATCH_KEY]:
self.btv = AndroidTVSync.from_base(self.btv)
Expand All @@ -473,7 +472,15 @@ def test_get_device_properties(self):
self.btv._cmd_current_app(),
constants.CMD_CURRENT_APP_GOOGLE_TV,
)
return
self.assertEqual(
self.btv._cmd_current_app_media_session_state(),
constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE_GOOGLE_TV,
)
self.assertEqual(
self.btv._cmd_launch_app("TEST"),
constants.CMD_LAUNCH_APP_GOOGLE_TV.format("TEST"),
)

with patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT_SONY_TV)[self.PATCH_KEY]:
device_properties = self.btv.get_device_properties()
self.assertDictEqual(DEVICE_PROPERTIES_DICT_SONY_TV, device_properties)
Expand Down

0 comments on commit 9ecd68b

Please sign in to comment.