Skip to content

Commit

Permalink
FireTV
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed May 8, 2020
1 parent d66a762 commit 8ab8f05
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 148 deletions.
30 changes: 15 additions & 15 deletions androidtv/firetv.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, host, port=5555, adbkey='', adb_server_ip='', adb_server_port
# Home Assistant Update #
# #
# ======================================================================= #
def update(self, get_running_apps=True):
async def update(self, get_running_apps=True):
"""Get the info needed for a Home Assistant update.
Parameters
Expand All @@ -61,7 +61,7 @@ def update(self, get_running_apps=True):
"""
# Get the properties needed for the update
screen_on, awake, wake_lock_size, current_app, media_session_state, running_apps = self.get_properties(get_running_apps=get_running_apps, lazy=True)
screen_on, awake, wake_lock_size, current_app, media_session_state, running_apps = await self.get_properties(get_running_apps=get_running_apps, lazy=True)

# Check if device is unavailable
if screen_on is None:
Expand Down Expand Up @@ -207,7 +207,7 @@ def update(self, get_running_apps=True):
# Properties #
# #
# ======================================================================= #
def get_properties(self, get_running_apps=True, lazy=False):
async def get_properties(self, get_running_apps=True, lazy=False):
"""Get the properties needed for Home Assistant updates.
This will send one of the following ADB commands:
Expand Down Expand Up @@ -242,14 +242,14 @@ def get_properties(self, get_running_apps=True, lazy=False):
"""
if lazy:
if get_running_apps:
output = self._adb.shell(constants.CMD_FIRETV_PROPERTIES_LAZY_RUNNING_APPS)
output = await self._adb.shell(constants.CMD_FIRETV_PROPERTIES_LAZY_RUNNING_APPS)
else:
output = self._adb.shell(constants.CMD_FIRETV_PROPERTIES_LAZY_NO_RUNNING_APPS)
output = await self._adb.shell(constants.CMD_FIRETV_PROPERTIES_LAZY_NO_RUNNING_APPS)
else:
if get_running_apps:
output = self._adb.shell(constants.CMD_FIRETV_PROPERTIES_NOT_LAZY_RUNNING_APPS)
output = await self._adb.shell(constants.CMD_FIRETV_PROPERTIES_NOT_LAZY_RUNNING_APPS)
else:
output = self._adb.shell(constants.CMD_FIRETV_PROPERTIES_NOT_LAZY_NO_RUNNING_APPS)
output = await self._adb.shell(constants.CMD_FIRETV_PROPERTIES_NOT_LAZY_NO_RUNNING_APPS)
_LOGGER.debug("Fire TV %s:%d `get_properties` response: %s", self.host, self.port, output)

# ADB command was unsuccessful
Expand Down Expand Up @@ -290,7 +290,7 @@ def get_properties(self, get_running_apps=True, lazy=False):

return screen_on, awake, wake_lock_size, current_app, media_session_state, running_apps

def get_properties_dict(self, get_running_apps=True, lazy=True):
async def get_properties_dict(self, get_running_apps=True, lazy=True):
"""Get the properties needed for Home Assistant updates and return them as a dictionary.
Parameters
Expand All @@ -307,7 +307,7 @@ def get_properties_dict(self, get_running_apps=True, lazy=True):
``'media_session_state'``, and ``'running_apps'``
"""
screen_on, awake, wake_lock_size, current_app, media_session_state, running_apps = self.get_properties(get_running_apps=get_running_apps, lazy=lazy)
screen_on, awake, wake_lock_size, current_app, media_session_state, running_apps = await self.get_properties(get_running_apps=get_running_apps, lazy=lazy)

return {'screen_on': screen_on,
'awake': awake,
Expand All @@ -316,7 +316,7 @@ def get_properties_dict(self, get_running_apps=True, lazy=True):
'media_session_state': media_session_state,
'running_apps': running_apps}

def running_apps(self):
async def running_apps(self):
"""Return a list of running user applications.
Returns
Expand All @@ -325,7 +325,7 @@ def running_apps(self):
A list of the running apps
"""
running_apps_response = self._adb.shell(constants.CMD_FIRETV_RUNNING_APPS)
running_apps_response = await self._adb.shell(constants.CMD_FIRETV_RUNNING_APPS)

return self._running_apps(running_apps_response)

Expand All @@ -334,10 +334,10 @@ def running_apps(self):
# turn on/off methods #
# #
# ======================================================================= #
def turn_on(self):
async def turn_on(self):
"""Send ``POWER`` and ``HOME`` actions if the device is off."""
self._adb.shell(constants.CMD_SCREEN_ON + " || (input keyevent {0} && input keyevent {1})".format(constants.KEY_POWER, constants.KEY_HOME))
await self._adb.shell(constants.CMD_SCREEN_ON + " || (input keyevent {0} && input keyevent {1})".format(constants.KEY_POWER, constants.KEY_HOME))

def turn_off(self):
async def turn_off(self):
"""Send ``SLEEP`` action if the device is not off."""
self._adb.shell(constants.CMD_SCREEN_ON + " && input keyevent {0}".format(constants.KEY_SLEEP))
await self._adb.shell(constants.CMD_SCREEN_ON + " && input keyevent {0}".format(constants.KEY_SLEEP))
Loading

0 comments on commit 8ab8f05

Please sign in to comment.