Skip to content

Commit

Permalink
Merge 28a8d82 into feec949
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed May 5, 2020
2 parents feec949 + 28a8d82 commit 165ea6e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 90 deletions.
14 changes: 4 additions & 10 deletions androidtv/androidtv.py
Expand Up @@ -50,7 +50,7 @@ def update(self, get_running_apps=True):
Parameters
----------
get_running_apps : bool
Whether or not to get the :attr:`~androidtv.basetv.BaseTV.running_apps` property
Whether or not to get the :meth:`~androidtv.androidtv.AndroidTV.running_apps` property
Returns
-------
Expand Down Expand Up @@ -180,7 +180,7 @@ def update(self, get_running_apps=True):

# ======================================================================= #
# #
# properties #
# Properties #
# #
# ======================================================================= #
def get_properties(self, get_running_apps=True, lazy=False):
Expand All @@ -194,7 +194,7 @@ def get_properties(self, get_running_apps=True, lazy=False):
Parameters
----------
get_running_apps : bool
Whether or not to get the :attr:`~androidtv.basetv.BaseTV.running_apps` property
Whether or not to get the :meth:`~androidtv.androidtv.AndroidTV.running_apps` property
lazy : bool
Whether or not to continue retrieving properties if the device is off or the screensaver is running
Expand Down Expand Up @@ -302,7 +302,7 @@ def get_properties_dict(self, get_running_apps=True, lazy=True):
Parameters
----------
get_running_apps : bool
Whether or not to get the :attr:`~androidtv.basetv.BaseTV.running_apps` property
Whether or not to get the :meth:`~androidtv.androidtv.AndroidTV.running_apps` property
lazy : bool
Whether or not to continue retrieving properties if the device is off or the screensaver is running
Expand All @@ -326,12 +326,6 @@ def get_properties_dict(self, get_running_apps=True, lazy=True):
'volume': volume,
'running_apps': running_apps}

# ======================================================================= #
# #
# Properties #
# #
# ======================================================================= #
@property
def running_apps(self):
"""Return a list of running user applications.
Expand Down
42 changes: 16 additions & 26 deletions androidtv/basetv.py
Expand Up @@ -104,6 +104,18 @@ def __init__(self, host, port=5555, adbkey='', adb_server_ip='', adb_server_port
# ADB methods #
# #
# ======================================================================= #
@property
def available(self):
"""Whether the ADB connection is intact.
Returns
-------
bool
Whether or not the ADB connection is intact
"""
return self._adb.available

def adb_shell(self, cmd):
"""Send an ADB command.
Expand Down Expand Up @@ -356,7 +368,6 @@ def _conditions_are_true(conditions, media_session_state=None, wake_lock_size=No
# Properties #
# #
# ======================================================================= #
@property
def audio_output_device(self):
"""Get the current audio playback device.
Expand All @@ -370,7 +381,6 @@ def audio_output_device(self):

return self._audio_output_device(stream_music)

@property
def audio_state(self):
"""Check if audio is playing, paused, or idle.
Expand All @@ -383,19 +393,6 @@ def audio_state(self):
audio_state_response = self._adb.shell(constants.CMD_AUDIO_STATE)
return self._audio_state(audio_state_response)

@property
def available(self):
"""Check whether the ADB connection is intact.
Returns
-------
bool
Whether or not the ADB connection is intact
"""
return self._adb.available

@property
def awake(self):
"""Check if the device is awake (screensaver is not running).
Expand All @@ -407,7 +404,6 @@ def awake(self):
"""
return self._adb.shell(constants.CMD_AWAKE + constants.CMD_SUCCESS1_FAILURE0) == '1'

@property
def current_app(self):
"""Return the current app.
Expand All @@ -421,7 +417,6 @@ def current_app(self):

return self._current_app(current_app_response)

@property
def is_volume_muted(self):
"""Whether or not the volume is muted.
Expand All @@ -435,7 +430,6 @@ def is_volume_muted(self):

return self._is_volume_muted(stream_music)

@property
def media_session_state(self):
"""Get the state from the output of ``dumpsys media_session``.
Expand All @@ -451,7 +445,6 @@ def media_session_state(self):

return media_session_state

@property
def screen_on(self):
"""Check if the screen is on.
Expand All @@ -463,7 +456,6 @@ def screen_on(self):
"""
return self._adb.shell(constants.CMD_SCREEN_ON + constants.CMD_SUCCESS1_FAILURE0) == '1'

@property
def volume(self):
"""Get the absolute volume level.
Expand All @@ -478,7 +470,6 @@ def volume(self):

return self._volume(stream_music, audio_output_device)

@property
def volume_level(self):
"""Get the relative volume level.
Expand All @@ -488,11 +479,10 @@ def volume_level(self):
The volume level (between 0 and 1), or ``None`` if it could not be determined
"""
volume = self.volume
volume = self.volume()

return self._volume_level(volume)

@property
def wake_lock_size(self):
"""Get the size of the current wake lock.
Expand Down Expand Up @@ -1120,7 +1110,7 @@ def set_volume_level(self, volume_level):
"""
# if necessary, determine the max volume
if not self.max_volume:
_ = self.volume
_ = self.volume()
if not self.max_volume:
return None

Expand All @@ -1146,7 +1136,7 @@ def volume_up(self, current_volume_level=None):
"""
if current_volume_level is None or not self.max_volume:
current_volume = self.volume
current_volume = self.volume()
else:
current_volume = round(self.max_volume * current_volume_level)

Expand Down Expand Up @@ -1175,7 +1165,7 @@ def volume_down(self, current_volume_level=None):
"""
if current_volume_level is None or not self.max_volume:
current_volume = self.volume
current_volume = self.volume()
else:
current_volume = round(self.max_volume * current_volume_level)

Expand Down
1 change: 0 additions & 1 deletion androidtv/firetv.py
Expand Up @@ -323,7 +323,6 @@ def get_properties_dict(self, get_running_apps=True, lazy=True):
# Properties #
# #
# ======================================================================= #
@property
def running_apps(self):
"""Return a list of running user applications.
Expand Down
56 changes: 28 additions & 28 deletions tests/test_androidtv.py
Expand Up @@ -316,78 +316,78 @@ def test_running_apps(self):
"""
with patchers.patch_shell(None)[self.PATCH_KEY]:
running_apps = self.atv.running_apps
running_apps = self.atv.running_apps()
self.assertIsNone(running_apps, None)

with patchers.patch_shell('')[self.PATCH_KEY]:
running_apps = self.atv.running_apps
running_apps = self.atv.running_apps()
self.assertIsNone(running_apps, None)

with patchers.patch_shell(RUNNING_APPS_OUTPUT)[self.PATCH_KEY]:
running_apps = self.atv.running_apps
running_apps = self.atv.running_apps()
self.assertListEqual(running_apps, RUNNING_APPS_LIST)

def test_audio_output_device(self):
"""Check that the ``device`` property works correctly.
"""
with patchers.patch_shell(None)[self.PATCH_KEY]:
audio_output_device = self.atv.audio_output_device
audio_output_device = self.atv.audio_output_device()
self.assertIsNone(audio_output_device)

with patchers.patch_shell('')[self.PATCH_KEY]:
audio_output_device = self.atv.audio_output_device
audio_output_device = self.atv.audio_output_device()
self.assertIsNone(audio_output_device)

with patchers.patch_shell(' ')[self.PATCH_KEY]:
audio_output_device = self.atv.audio_output_device
audio_output_device = self.atv.audio_output_device()
self.assertIsNone(audio_output_device)

with patchers.patch_shell(STREAM_MUSIC_EMPTY)[self.PATCH_KEY]:
audio_output_device = self.atv.audio_output_device
audio_output_device = self.atv.audio_output_device()
self.assertIsNone(audio_output_device)

with patchers.patch_shell(STREAM_MUSIC_OFF)[self.PATCH_KEY]:
audio_output_device = self.atv.audio_output_device
audio_output_device = self.atv.audio_output_device()
self.assertEqual('speaker', audio_output_device)

with patchers.patch_shell(STREAM_MUSIC_ON)[self.PATCH_KEY]:
audio_output_device = self.atv.audio_output_device
audio_output_device = self.atv.audio_output_device()
self.assertEqual('hmdi_arc', audio_output_device)

def test_volume(self):
"""Check that the ``volume`` property works correctly.
"""
with patchers.patch_shell(None)[self.PATCH_KEY]:
volume = self.atv.volume
volume = self.atv.volume()
self.assertIsNone(volume)

with patchers.patch_shell('')[self.PATCH_KEY]:
volume = self.atv.volume
volume = self.atv.volume()
self.assertIsNone(volume)

with patchers.patch_shell(' ')[self.PATCH_KEY]:
volume = self.atv.volume
volume = self.atv.volume()
self.assertIsNone(volume)

with patchers.patch_shell(STREAM_MUSIC_EMPTY)[self.PATCH_KEY]:
volume = self.atv.volume
volume = self.atv.volume()
self.assertIsNone(volume)

with patchers.patch_shell(STREAM_MUSIC_NO_VOLUME)[self.PATCH_KEY]:
volume = self.atv.volume
volume = self.atv.volume()
self.assertIsNone(volume)

self.atv.max_volume = None
with patchers.patch_shell(STREAM_MUSIC_OFF)[self.PATCH_KEY]:
volume = self.atv.volume
volume = self.atv.volume()
self.assertEqual(volume, 20)
self.assertEqual(self.atv.max_volume, 60.)

self.atv.max_volume = None
with patchers.patch_shell(STREAM_MUSIC_ON)[self.PATCH_KEY]:
volume = self.atv.volume
volume = self.atv.volume()
self.assertEqual(volume, 22)
self.assertEqual(self.atv.max_volume, 60.)

Expand All @@ -396,34 +396,34 @@ def test_volume_level(self):
"""
with patchers.patch_shell(None)[self.PATCH_KEY]:
volume_level = self.atv.volume_level
volume_level = self.atv.volume_level()
self.assertIsNone(volume_level)

with patchers.patch_shell('')[self.PATCH_KEY]:
volume_level = self.atv.volume_level
volume_level = self.atv.volume_level()
self.assertIsNone(volume_level)

with patchers.patch_shell(' ')[self.PATCH_KEY]:
volume_level = self.atv.volume_level
volume_level = self.atv.volume_level()
self.assertIsNone(volume_level)

with patchers.patch_shell(STREAM_MUSIC_EMPTY)[self.PATCH_KEY]:
volume_level = self.atv.volume_level
volume_level = self.atv.volume_level()
self.assertIsNone(volume_level)

with patchers.patch_shell(STREAM_MUSIC_NO_VOLUME)[self.PATCH_KEY]:
volume_level = self.atv.volume_level
volume_level = self.atv.volume_level()
self.assertIsNone(volume_level)

self.atv.max_volume = None
with patchers.patch_shell(STREAM_MUSIC_OFF)[self.PATCH_KEY]:
volume_level = self.atv.volume_level
volume_level = self.atv.volume_level()
self.assertEqual(volume_level, 20./60)
self.assertEqual(self.atv.max_volume, 60.)

self.atv.max_volume = None
with patchers.patch_shell(STREAM_MUSIC_ON)[self.PATCH_KEY]:
volume_level = self.atv.volume_level
volume_level = self.atv.volume_level()
self.assertEqual(volume_level, 22./60)
self.assertEqual(self.atv.max_volume, 60.)

Expand All @@ -432,23 +432,23 @@ def test_is_volume_muted(self):
"""
with patchers.patch_shell(None)[self.PATCH_KEY]:
is_volume_muted = self.atv.is_volume_muted
is_volume_muted = self.atv.is_volume_muted()
self.assertIsNone(is_volume_muted)

with patchers.patch_shell('')[self.PATCH_KEY]:
is_volume_muted = self.atv.is_volume_muted
is_volume_muted = self.atv.is_volume_muted()
self.assertIsNone(is_volume_muted)

with patchers.patch_shell(' ')[self.PATCH_KEY]:
is_volume_muted = self.atv.is_volume_muted
is_volume_muted = self.atv.is_volume_muted()
self.assertIsNone(is_volume_muted)

with patchers.patch_shell(STREAM_MUSIC_EMPTY)[self.PATCH_KEY]:
is_volume_muted = self.atv.is_volume_muted
is_volume_muted = self.atv.is_volume_muted()
self.assertIsNone(is_volume_muted)

with patchers.patch_shell(STREAM_MUSIC_OFF)[self.PATCH_KEY]:
is_volume_muted = self.atv.is_volume_muted
is_volume_muted = self.atv.is_volume_muted()
self.assertFalse(is_volume_muted)

def test_set_volume_level(self):
Expand Down

0 comments on commit 165ea6e

Please sign in to comment.