Skip to content

Commit

Permalink
Remove unused STATE_* constants (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Apr 9, 2022
1 parent 0af6b3b commit bcc83db
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 64 deletions.
2 changes: 0 additions & 2 deletions androidtv/constants.py
Expand Up @@ -366,14 +366,12 @@ class DeviceEnum(IntEnum):


# Android TV / Fire TV states
STATE_ON = "on"
STATE_IDLE = "idle"
STATE_OFF = "off"
STATE_PLAYING = "playing"
STATE_PAUSED = "paused"
STATE_STANDBY = "standby"
STATE_STOPPED = "stopped"
STATE_UNKNOWN = "unknown"

#: States that are valid (used by :func:`~androidtv.basetv.state_detection_rules_validator`)
VALID_STATES = (STATE_IDLE, STATE_OFF, STATE_PLAYING, STATE_PAUSED, STATE_STANDBY)
Expand Down
32 changes: 17 additions & 15 deletions tests/test_androidtv_sync.py
Expand Up @@ -16,6 +16,8 @@
from . import patchers


UNKNOWN_APP = "unknown"

HDMI_INPUT_EMPTY = "\n"

STREAM_MUSIC_EMPTY = "- STREAM_MUSIC:\n \n- STREAM"
Expand Down Expand Up @@ -377,8 +379,8 @@ def test_update2(self):

self.atv._state_detection_rules = STATE_DETECTION_RULES4
state = self.atv.update()
self.assertEqual(state[0], constants.STATE_PAUSED)

self.assertEqual(state[0], constants.STATE_PAUSED)
self.atv._state_detection_rules = STATE_DETECTION_RULES5
state = self.atv.update()
self.assertEqual(state[0], constants.STATE_IDLE)
Expand Down Expand Up @@ -566,38 +568,38 @@ def test_state_detection(self):

# Unknown app
self.assertUpdate(
[True, True, constants.STATE_IDLE, 2, "unknown", 2, "hmdi_arc", False, 30, None, None],
(constants.STATE_PAUSED, "unknown", ["unknown"], "hmdi_arc", False, 0.5, None),
[True, True, constants.STATE_IDLE, 2, UNKNOWN_APP, 2, "hmdi_arc", False, 30, None, None],
(constants.STATE_PAUSED, UNKNOWN_APP, [UNKNOWN_APP], "hmdi_arc", False, 0.5, None),
)

self.assertUpdate(
[True, True, constants.STATE_IDLE, 2, "unknown", 3, "hmdi_arc", False, 30, None, None],
(constants.STATE_PLAYING, "unknown", ["unknown"], "hmdi_arc", False, 0.5, None),
[True, True, constants.STATE_IDLE, 2, UNKNOWN_APP, 3, "hmdi_arc", False, 30, None, None],
(constants.STATE_PLAYING, UNKNOWN_APP, [UNKNOWN_APP], "hmdi_arc", False, 0.5, None),
)

self.assertUpdate(
[True, True, constants.STATE_IDLE, 2, "unknown", 4, "hmdi_arc", False, 30, None, None],
(constants.STATE_IDLE, "unknown", ["unknown"], "hmdi_arc", False, 0.5, None),
[True, True, constants.STATE_IDLE, 2, UNKNOWN_APP, 4, "hmdi_arc", False, 30, None, None],
(constants.STATE_IDLE, UNKNOWN_APP, [UNKNOWN_APP], "hmdi_arc", False, 0.5, None),
)

self.assertUpdate(
[True, True, constants.STATE_PLAYING, 2, "unknown", None, "hmdi_arc", False, 30, None, None],
(constants.STATE_PLAYING, "unknown", ["unknown"], "hmdi_arc", False, 0.5, None),
[True, True, constants.STATE_PLAYING, 2, UNKNOWN_APP, None, "hmdi_arc", False, 30, None, None],
(constants.STATE_PLAYING, UNKNOWN_APP, [UNKNOWN_APP], "hmdi_arc", False, 0.5, None),
)

self.assertUpdate(
[True, True, constants.STATE_IDLE, 1, "unknown", None, "hmdi_arc", False, 30, None, None],
(constants.STATE_PAUSED, "unknown", ["unknown"], "hmdi_arc", False, 0.5, None),
[True, True, constants.STATE_IDLE, 1, UNKNOWN_APP, None, "hmdi_arc", False, 30, None, None],
(constants.STATE_PAUSED, UNKNOWN_APP, [UNKNOWN_APP], "hmdi_arc", False, 0.5, None),
)

self.assertUpdate(
[True, True, constants.STATE_IDLE, 2, "unknown", None, "hmdi_arc", False, 30, None, None],
(constants.STATE_PLAYING, "unknown", ["unknown"], "hmdi_arc", False, 0.5, None),
[True, True, constants.STATE_IDLE, 2, UNKNOWN_APP, None, "hmdi_arc", False, 30, None, None],
(constants.STATE_PLAYING, UNKNOWN_APP, [UNKNOWN_APP], "hmdi_arc", False, 0.5, None),
)

self.assertUpdate(
[True, True, constants.STATE_IDLE, 3, "unknown", None, "hmdi_arc", False, 30, None, None],
(constants.STATE_IDLE, "unknown", ["unknown"], "hmdi_arc", False, 0.5, None),
[True, True, constants.STATE_IDLE, 3, UNKNOWN_APP, None, "hmdi_arc", False, 30, None, None],
(constants.STATE_IDLE, UNKNOWN_APP, [UNKNOWN_APP], "hmdi_arc", False, 0.5, None),
)

def test_customize_command(self):
Expand Down
41 changes: 9 additions & 32 deletions tests/test_basetv_sync.py
Expand Up @@ -117,10 +117,7 @@
package:org.example.launcher
"""

INSTALLED_APPS_LIST = [
"org.example.app",
"org.example.launcher",
]
INSTALLED_APPS_LIST = ["org.example.app", "org.example.launcher"]

MEDIA_SESSION_STATE_OUTPUT = "com.amazon.tv.launcher\nstate=PlaybackState {state=2, position=0, buffered position=0, speed=0.0, updated=65749, actions=240640, custom actions=[], active item id=-1, error=null}"

Expand Down Expand Up @@ -497,18 +494,11 @@ def test_get_device_properties(self):
assert "Chromecast" in self.btv.device_properties.get("model", "")
assert self.btv.DEVICE_ENUM == AndroidTVSync.DEVICE_ENUM
self.assertEqual(self.btv.device_properties["manufacturer"], "Google")
self.assertEqual(self.btv._cmd_current_app(), constants.CMD_CURRENT_APP_GOOGLE_TV)
self.assertEqual(
self.btv._cmd_current_app(),
constants.CMD_CURRENT_APP_GOOGLE_TV,
)
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"),
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 patch.object(
self.btv._adb, "shell", side_effect=(DEVICE_PROPERTIES_OUTPUT_SONY_TV, ETHMAC_SONY, WIFIMAC_SONY)
Expand All @@ -527,30 +517,17 @@ def test_get_device_properties(self):
assert self.btv.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV
self.assertDictEqual(DEVICE_PROPERTIES_DICT_SHIELD_TV_11, device_properties)
# _cmd_audio_state
self.assertEqual(
self.btv._cmd_audio_state(),
constants.CMD_AUDIO_STATE11,
)
self.assertEqual(self.btv._cmd_audio_state(), constants.CMD_AUDIO_STATE11)
# _cmd_current_app
self.assertEqual(
self.btv._cmd_current_app(),
constants.CMD_CURRENT_APP11,
)
self.assertEqual(self.btv._cmd_current_app(), constants.CMD_CURRENT_APP11)
# _cmd_current_app_media_session_state
self.assertEqual(
self.btv._cmd_current_app_media_session_state(),
constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE11,
self.btv._cmd_current_app_media_session_state(), constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE11
)
# _cmd_hdmi_input
self.assertEqual(
self.btv._cmd_hdmi_input(),
constants.CMD_HDMI_INPUT11,
)
self.assertEqual(self.btv._cmd_hdmi_input(), constants.CMD_HDMI_INPUT11)
# _cmd_launch_app
self.assertEqual(
self.btv._cmd_launch_app("TEST"),
constants.CMD_LAUNCH_APP11.format("TEST"),
)
self.assertEqual(self.btv._cmd_launch_app("TEST"), constants.CMD_LAUNCH_APP11.format("TEST"))

def test_get_installed_apps(self):
""" "Check that `get_installed_apps` works correctly."""
Expand Down
17 changes: 12 additions & 5 deletions tests/test_firetv_sync.py
Expand Up @@ -16,6 +16,8 @@
from . import patchers


UNKNOWN_APP = "unknown"

HDMI_INPUT_EMPTY = "\n"

CURRENT_APP_OUTPUT = "com.amazon.tv.launcher"
Expand Down Expand Up @@ -363,23 +365,28 @@ def test_state_detection(self):

# Unknown app
self.assertUpdate(
[True, True, 1, "unknown", 3, ["unknown"], None], (constants.STATE_PLAYING, "unknown", ["unknown"], None)
[True, True, 1, UNKNOWN_APP, 3, [UNKNOWN_APP], None],
(constants.STATE_PLAYING, UNKNOWN_APP, [UNKNOWN_APP], None),
)

self.assertUpdate(
[True, True, 1, "unknown", 2, ["unknown"], None], (constants.STATE_PAUSED, "unknown", ["unknown"], None)
[True, True, 1, UNKNOWN_APP, 2, [UNKNOWN_APP], None],
(constants.STATE_PAUSED, UNKNOWN_APP, [UNKNOWN_APP], None),
)

self.assertUpdate(
[True, True, 1, "unknown", 1, ["unknown"], None], (constants.STATE_IDLE, "unknown", ["unknown"], None)
[True, True, 1, UNKNOWN_APP, 1, [UNKNOWN_APP], None],
(constants.STATE_IDLE, UNKNOWN_APP, [UNKNOWN_APP], None),
)

self.assertUpdate(
[True, True, 1, "unknown", None, ["unknown"], None], (constants.STATE_PLAYING, "unknown", ["unknown"], None)
[True, True, 1, UNKNOWN_APP, None, [UNKNOWN_APP], None],
(constants.STATE_PLAYING, UNKNOWN_APP, [UNKNOWN_APP], None),
)

self.assertUpdate(
[True, True, 2, "unknown", None, ["unknown"], None], (constants.STATE_PAUSED, "unknown", ["unknown"], None)
[True, True, 2, UNKNOWN_APP, None, [UNKNOWN_APP], None],
(constants.STATE_PAUSED, UNKNOWN_APP, [UNKNOWN_APP], None),
)


Expand Down
12 changes: 2 additions & 10 deletions tests/test_homeassistant_sync.py
Expand Up @@ -10,12 +10,7 @@

sys.path.insert(0, "..")

from adb_shell.exceptions import (
InvalidChecksumError,
InvalidCommandError,
InvalidResponseError,
TcpTimeoutException,
)
from adb_shell.exceptions import InvalidChecksumError, InvalidCommandError, InvalidResponseError, TcpTimeoutException
from androidtv import setup
from androidtv.constants import APPS, KEYS, STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING, STATE_STANDBY
from androidtv.exceptions import LockNotAcquiredException
Expand Down Expand Up @@ -508,10 +503,7 @@ def test_reconnect(self):

assert (
"ADB connection to {}:{} via ADB server {}:{} successfully established".format(
self.aftv.aftv.host,
self.aftv.aftv.port,
self.aftv.aftv.adb_server_ip,
self.aftv.aftv.adb_server_port,
self.aftv.aftv.host, self.aftv.aftv.port, self.aftv.aftv.adb_server_ip, self.aftv.aftv.adb_server_port
)
in logs.output[0]
)
Expand Down

0 comments on commit bcc83db

Please sign in to comment.