Skip to content

Commit

Permalink
Merge 8fc1f2f into feec949
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed May 6, 2020
2 parents feec949 + 8fc1f2f commit fb17b69
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 109 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
62 changes: 26 additions & 36 deletions androidtv/basetv.py
Expand Up @@ -41,8 +41,8 @@ class BaseTV(object):
**Valid rules:**
* ``'standby'``, ``'playing'``, ``'paused'``, ``'idle'``, or ``'off'`` = always report the specified state when this app is open
* ``'media_session_state'`` = try to use the :attr:`media_session_state` property to determine the state
* ``'audio_state'`` = try to use the :attr:`audio_state` property to determine the state
* ``'media_session_state'`` = try to use the :meth:`media_session_state` property to determine the state
* ``'audio_state'`` = try to use the :meth:`audio_state` property to determine the state
* ``{'<VALID_STATE>': {'<PROPERTY1>': VALUE1, '<PROPERTY2>': VALUE2, ...}}`` = check if each of the properties is equal to the specified value, and if so return the state
* The valid properties are ``'media_session_state'``, ``'audio_state'``, and ``'wake_lock_size'``
Expand Down 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 @@ -266,13 +278,13 @@ def _custom_state_detection(self, current_app=None, media_session_state=None, wa
Parameters
----------
current_app : str, None
The :attr:`current_app` property
The :meth:`current_app` property
media_session_state : int, None
The :attr:`media_session_state` property
The :meth:`media_session_state` property
wake_lock_size : int, None
The :attr:`wake_lock_size` property
The :meth:`wake_lock_size` property
audio_state : str, None
The :attr:`audio_state` property
The :meth:`audio_state` property
Returns
-------
Expand Down Expand Up @@ -320,11 +332,11 @@ def _conditions_are_true(conditions, media_session_state=None, wake_lock_size=No
conditions : dict
A dictionary of conditions to be checked (see the ``state_detection_rules`` parameter in :class:`~androidtv.basetv.BaseTV`)
media_session_state : int, None
The :attr:`media_session_state` property
The :meth:`media_session_state` property
wake_lock_size : int, None
The :attr:`wake_lock_size` property
The :meth:`wake_lock_size` property
audio_state : str, None
The :attr:`audio_state` property
The :meth:`audio_state` property
Returns
-------
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 @@ -537,7 +527,7 @@ def _audio_output_device(stream_music):

@staticmethod
def _audio_state(audio_state_response):
"""Parse the :attr:`audio_state` property from the output of the command :py:const:`androidtv.constants.CMD_AUDIO_STATE`.
"""Parse the :meth:`audio_state` property from the output of the command :py:const:`androidtv.constants.CMD_AUDIO_STATE`.
Parameters
----------
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
14 changes: 4 additions & 10 deletions androidtv/firetv.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.firetv.FireTV.running_apps` property
Returns
-------
Expand Down Expand Up @@ -206,7 +206,7 @@ def update(self, get_running_apps=True):

# ======================================================================= #
# #
# properties #
# Properties #
# #
# ======================================================================= #
def get_properties(self, get_running_apps=True, lazy=False):
Expand All @@ -222,7 +222,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.firetv.FireTV.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 @@ -298,7 +298,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.firetv.FireTV.running_apps` property
lazy : bool
Whether or not to continue retrieving properties if the device is off or the screensaver is running
Expand All @@ -318,12 +318,6 @@ def get_properties_dict(self, get_running_apps=True, lazy=True):
'media_session_state': media_session_state,
'running_apps': running_apps}

# ======================================================================= #
# #
# Properties #
# #
# ======================================================================= #
@property
def running_apps(self):
"""Return a list of running user applications.
Expand Down

0 comments on commit fb17b69

Please sign in to comment.