Skip to content

Commit

Permalink
Store the installed apps and device properties (#228)
Browse files Browse the repository at this point in the history
* Store the installed apps and device properties

* Documentation
  • Loading branch information
JeffLIrion committed Jan 16, 2021
1 parent 9a3021e commit 41983c6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
10 changes: 5 additions & 5 deletions androidtv/__init__.py
Expand Up @@ -46,15 +46,15 @@ def setup(host, port=5555, adbkey='', adb_server_ip='', adb_server_port=5037, st
if device_class == 'androidtv':
atv = AndroidTVSync(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)
atv.adb_connect(auth_timeout_s=auth_timeout_s)
atv.device_properties = atv.get_device_properties()
atv.installed_apps = atv.get_installed_apps()
atv.get_device_properties()
atv.get_installed_apps()
return atv

if device_class == 'firetv':
ftv = FireTVSync(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)
ftv.adb_connect(auth_timeout_s=auth_timeout_s)
ftv.device_properties = ftv.get_device_properties()
ftv.installed_apps = ftv.get_installed_apps()
ftv.get_device_properties()
ftv.get_installed_apps()
return ftv

if device_class != 'auto':
Expand All @@ -69,7 +69,7 @@ def setup(host, port=5555, adbkey='', adb_server_ip='', adb_server_port=5037, st
aftv.device_properties = aftv.get_device_properties()

# get the installed apps
aftv.installed_apps = aftv.get_installed_apps()
aftv.get_installed_apps()

# Fire TV
if aftv.device_properties.get('manufacturer') == 'Amazon':
Expand Down
26 changes: 13 additions & 13 deletions androidtv/basetv/basetv.py
Expand Up @@ -135,20 +135,20 @@ def _parse_device_properties(self, properties):
properties : str, None
The output of the ADB command that retrieves the device properties
Returns
-------
dict
A dictionary with keys ``'wifimac'``, ``'ethmac'``, ``'serialno'``, ``'manufacturer'``, ``'model'``, and ``'sw_version'``
This method fills in the ``device_properties`` attribute, which is a dictionary with keys
``'wifimac'``, ``'ethmac'``, ``'serialno'``, ``'manufacturer'``, ``'model'``, and ``'sw_version'``
"""
_LOGGER.debug("%s:%d `get_device_properties` response: %s", self.host, self.port, properties)

if not properties:
return {}
self.device_properties = {}
return

lines = properties.strip().splitlines()
if len(lines) != 6:
return {}
self.device_properties = {}
return

manufacturer, model, serialno, version, mac_wlan0_output, mac_eth0_output = lines

Expand All @@ -172,12 +172,12 @@ def _parse_device_properties(self, properties):
else:
ethmac = None

return {'manufacturer': manufacturer,
'model': model,
'serialno': serialno,
'sw_version': version,
'wifimac': wifimac,
'ethmac': ethmac}
self.device_properties = {'manufacturer': manufacturer,
'model': model,
'serialno': serialno,
'sw_version': version,
'wifimac': wifimac,
'ethmac': ethmac}

# ======================================================================= #
# #
Expand Down Expand Up @@ -395,7 +395,7 @@ def _get_hdmi_input(hdmi_response):
return hdmi_response.strip() if hdmi_response and hdmi_response.strip() else None

@staticmethod
def _installed_apps(installed_apps_response):
def _get_installed_apps(installed_apps_response):
"""Get the installed apps from the output of :py:const:`androidtv.constants.CMD_INSTALLED_APPS`.
Parameters
Expand Down
6 changes: 4 additions & 2 deletions androidtv/basetv/basetv_async.py
Expand Up @@ -198,7 +198,8 @@ async def get_device_properties(self):
constants.CMD_MAC_WLAN0 + " && " +
constants.CMD_MAC_ETH0)

return self._parse_device_properties(properties)
self._parse_device_properties(properties)
return self.device_properties

# ======================================================================= #
# #
Expand Down Expand Up @@ -275,7 +276,8 @@ async def get_installed_apps(self):
"""
installed_apps_response = await self._adb.shell(constants.CMD_INSTALLED_APPS)
return self._installed_apps(installed_apps_response)
self.installed_apps = self._get_installed_apps(installed_apps_response)
return self.installed_apps

async def is_volume_muted(self):
"""Whether or not the volume is muted.
Expand Down
6 changes: 4 additions & 2 deletions androidtv/basetv/basetv_sync.py
Expand Up @@ -198,7 +198,8 @@ def get_device_properties(self):
constants.CMD_MAC_WLAN0 + " && " +
constants.CMD_MAC_ETH0)

return self._parse_device_properties(properties)
self._parse_device_properties(properties)
return self.device_properties

# ======================================================================= #
# #
Expand Down Expand Up @@ -275,7 +276,8 @@ def get_installed_apps(self):
"""
installed_apps_response = self._adb.shell(constants.CMD_INSTALLED_APPS)
return self._installed_apps(installed_apps_response)
self.installed_apps = self._get_installed_apps(installed_apps_response)
return self.installed_apps

def is_volume_muted(self):
"""Whether or not the volume is muted.
Expand Down
12 changes: 6 additions & 6 deletions androidtv/setup_async.py
Expand Up @@ -42,15 +42,15 @@ async def setup(host, port=5555, adbkey='', adb_server_ip='', adb_server_port=50
if device_class == 'androidtv':
atv = AndroidTVAsync(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)
await atv.adb_connect(auth_timeout_s=auth_timeout_s)
atv.device_properties = await atv.get_device_properties()
atv.installed_apps = await atv.get_installed_apps()
await atv.get_device_properties()
await atv.get_installed_apps()
return atv

if device_class == 'firetv':
ftv = FireTVAsync(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)
await ftv.adb_connect(auth_timeout_s=auth_timeout_s)
ftv.device_properties = await ftv.get_device_properties()
ftv.installed_apps = await ftv.get_installed_apps()
await ftv.get_device_properties()
await ftv.get_installed_apps()
return ftv

if device_class != 'auto':
Expand All @@ -62,10 +62,10 @@ async def setup(host, port=5555, adbkey='', adb_server_ip='', adb_server_port=50
await aftv.adb_connect(auth_timeout_s=auth_timeout_s)

# get device properties
aftv.device_properties = await aftv.get_device_properties()
await aftv.get_device_properties()

# get the installed apps
aftv.installed_apps = await aftv.get_installed_apps()
await aftv.get_installed_apps()

# Fire TV
if aftv.device_properties.get('manufacturer') == 'Amazon':
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basetv_async.py
Expand Up @@ -291,7 +291,7 @@ async def test_get_installed_apps(self):
"""
with async_patchers.patch_shell(None)[self.PATCH_KEY]:
with patch_calls(self.btv, self.btv._installed_apps) as patched:
with patch_calls(self.btv, self.btv._get_installed_apps) as patched:
await self.btv.get_installed_apps()
assert patched.called

Expand Down

0 comments on commit 41983c6

Please sign in to comment.