androidtv Documentation¶
androidtv¶
androidtv package¶
Submodules¶
androidtv.androidtv module¶
Communicate with an Android TV device via ADB over a network.
ADB Debugging must be enabled.
-
class
androidtv.androidtv.
AndroidTV
(host, adbkey='', adb_server_ip='', adb_server_port=5037)[source]¶ Bases:
androidtv.basetv.BaseTV
Representation of an Android TV device.
-
DEVICE_CLASS
= 'androidtv'¶
-
audio_state
¶ Check if audio is playing, paused, or idle.
Returns: The audio state, as determined from the ADB shell command dumpsys audio
, orNone
if it could not be determinedReturn type: str, None
-
device
¶ Get the current playback device.
Returns: The current playback device, or None
if it could not be determinedReturn type: str, None
-
get_properties
(lazy=False)[source]¶ Get the properties needed for Home Assistant updates.
Parameters: lazy (bool) – Whether or not to continue retrieving properties if the device is off or the screensaver is running Returns: - screen_on (bool, None) – Whether or not the device is on, or
None
if it was not determined - awake (bool, None) – Whether or not the device is awake (screensaver is not running), or
None
if it was not determined - wake_lock_size (int, None) – The size of the current wake lock, or
None
if it was not determined - media_session_state (int, None) – The state from the output of
dumpsys media_session
, orNone
if it was not determined - current_app (dict, None) – The current app property, or
None
if it was not determined - audio_state (str, None) – The audio state, as determined from “dumpsys audio”, or
None
if it was not determined - device (str, None) – The current playback device, or
None
if it was not determined - muted (bool, None) – Whether or not the volume is muted, or
None
if it was not determined - volume_level (int, None) – The absolute volume level, or
None
if it was not determined
- screen_on (bool, None) – Whether or not the device is on, or
-
get_properties_dict
(lazy=True)[source]¶ Get the properties needed for Home Assistant updates and return them as a dictionary.
Parameters: lazy (bool) – Whether or not to continue retrieving properties if the device is off or the screensaver is running Returns: A dictionary with keys 'screen_on'
,'awake'
,'wake_lock_size'
,'media_session_state'
,'current_app'
,'audio_state'
,'device'
,'muted'
, and'volume_level'
Return type: dict
-
muted
¶ Whether or not the volume is muted.
Returns: Whether or not the volume is muted, or None
if it could not be determinedReturn type: bool, None
-
start_intent
(uri)[source]¶ Start an intent on the device.
Parameters: uri (str) – The intent that will be sent is am start -a android.intent.action.VIEW -d <uri>
-
update
()[source]¶ Get the info needed for a Home Assistant update.
Returns: - state (str) – The state of the device
- current_app (str) – The current running app
- device (str) – The current playback device
- muted (bool) – Whether or not the volume is muted
- volume (float) – The volume level (between 0 and 1)
-
volume
¶ Get the relative volume level.
Returns: The volume level (between 0 and 1), or None
if it could not be determinedReturn type: float, None
-
volume_level
¶ Get the absolute volume level.
Returns: The absolute volume level, or None
if it could not be determinedReturn type: int, None
-
androidtv.basetv module¶
Communicate with an Android TV or Amazon Fire TV device via ADB over a network.
ADB Debugging must be enabled.
-
class
androidtv.basetv.
BaseTV
(host, adbkey='', adb_server_ip='', adb_server_port=5037)[source]¶ Bases:
object
Base class for representing an Android TV / Fire TV device.
-
_adb_shell_pure_python_adb
(cmd)[source]¶ Send an ADB command using an ADB server.
Parameters: cmd (str) – The ADB command to be sent Returns: The response from the device, if there is a response Return type: str, None
-
_adb_shell_python_adb
(cmd)[source]¶ Send an ADB command using the Python ADB implementation.
Parameters: cmd (str) – The ADB command to be sent Returns: The response from the device, if there is a response Return type: str, None
-
available
¶ Check whether the ADB connection is intact.
Returns: Whether or not the ADB connection is intact Return type: bool
-
awake
¶ Check if the device is awake (screensaver is not running).
Returns: Whether or not the device is awake (screensaver is not running) Return type: bool
-
connect
(always_log_errors=True)[source]¶ Connect to an Android TV / Fire TV device.
Parameters: always_log_errors (bool) – If True, errors will always be logged; otherwise, errors will only be logged on the first failed reconnect attempt Returns: Whether or not the connection was successfully established and the device is available Return type: bool
-
current_app
¶ Return the current app.
Returns: A dictionary with keys 'package'
and'activity'
if the current app was found; otherwise,None
Return type: dict
-
get_device_properties
()[source]¶ Return a dictionary of device properties.
Returns: props – A dictionary with keys 'wifimac'
,'ethmac'
,'serialno'
,'manufacturer'
,'model'
, and'sw_version'
Return type: dict
-
manufacturer
¶ Get the ‘manufacturer’ property from the device.
Returns: The manufacturer of the device Return type: str, None
-
media_session_state
¶ Get the state from the output of
dumpsys media_session
.Returns: The state from the output of the ADB shell command dumpsys media_session
, orNone
if it could not be determinedReturn type: int, None
Send menu action.
-
screen_on
¶ Check if the screen is on.
Returns: Whether or not the device is on Return type: bool
-
wake_lock
¶ Check for wake locks (device is playing).
Returns: Whether or not the wake_lock_size
property is equal to 1.Return type: bool
-
wake_lock_size
¶ Get the size of the current wake lock.
Returns: The size of the current wake lock, or None
if it could not be determinedReturn type: int, None
-
androidtv.constants module¶
Constants used in the BaseTV
, AndroidTV
, and FireTV
classes.
androidtv.firetv module¶
Communicate with an Amazon Fire TV device via ADB over a network.
ADB Debugging must be enabled.
-
class
androidtv.firetv.
FireTV
(host, adbkey='', adb_server_ip='', adb_server_port=5037)[source]¶ Bases:
androidtv.basetv.BaseTV
Representation of an Amazon Fire TV device.
-
DEVICE_CLASS
= 'firetv'¶
-
_send_intent
(pkg, intent, count=1)[source]¶ Send an intent to the device.
Parameters: - pkg (str) – The command that will be sent is
monkey -p <intent> -c <pkg> <count>; echo $?
- intent (str) – The command that will be sent is
monkey -p <intent> -c <pkg> <count>; echo $?
- count (int, str) – The command that will be sent is
monkey -p <intent> -c <pkg> <count>; echo $?
Returns: A dictionary with keys
'output'
and'retcode'
, if they could be determined; otherwise, an empty dictionaryReturn type: dict
- pkg (str) – The command that will be sent is
-
get_properties
(get_running_apps=True, lazy=False)[source]¶ Get the properties needed for Home Assistant updates.
Parameters: - get_running_apps (bool) – Whether or not to get the
running_apps
property - lazy (bool) – Whether or not to continue retrieving properties if the device is off or the screensaver is running
Returns: - screen_on (bool, None) – Whether or not the device is on, or
None
if it was not determined - awake (bool, None) – Whether or not the device is awake (screensaver is not running), or
None
if it was not determined - wake_lock_size (int, None) – The size of the current wake lock, or
None
if it was not determined - media_session_state (int, None) – The state from the output of
dumpsys media_session
, orNone
if it was not determined - current_app (dict, None) – The current app property, or
None
if it was not determined - running_apps (list, None) – A list of the running apps, or
None
if it was not determined
- get_running_apps (bool) – Whether or not to get the
-
get_properties_dict
(get_running_apps=True, lazy=True)[source]¶ Get the properties needed for Home Assistant updates and return them as a dictionary.
Parameters: - get_running_apps (bool) – Whether or not to get the
running_apps
property - lazy (bool) – Whether or not to continue retrieving properties if the device is off or the screensaver is running
Returns: A dictionary with keys
'screen_on'
,'awake'
,'wake_lock_size'
,'media_session_state'
,'current_app'
, and'running_apps'
Return type: dict
- get_running_apps (bool) – Whether or not to get the
-
launch_app
(app)[source]¶ Launch an app.
Parameters: app (str) – The ID of the app that will be launched Returns: A dictionary with keys 'output'
and'retcode'
, if they could be determined; otherwise, an empty dictionaryReturn type: dict
-
running_apps
¶ Return a list of running user applications.
Returns: A list of the running apps Return type: list
-
stop_app
(app)[source]¶ Stop an app.
Parameters: app (str) – The ID of the app that will be stopped Returns: The output of the am force-stop
ADB shell command, orNone
if the device is unavailableReturn type: str, None
-
update
(get_running_apps=True)[source]¶ Get the info needed for a Home Assistant update.
Parameters: get_running_apps (bool) – Whether or not to get the running_apps
propertyReturns: - state (str) – The state of the device
- current_app (str) – The current running app
- running_apps (list) – A list of the running apps if
get_running_apps
is True, otherwise the list[current_app]
-
Module contents¶
Connect to a device and determine whether it’s an Android TV or an Amazon Fire TV.
ADB Debugging must be enabled.
-
androidtv.
setup
(host, adbkey='', adb_server_ip='', adb_server_port=5037, device_class='auto')[source]¶ Connect to a device and determine whether it’s an Android TV or an Amazon Fire TV.
Parameters: - host (str) – The address of the device in the format
<ip address>:<host>
- adbkey (str) – The path to the
adbkey
file for ADB authentication; the fileadbkey.pub
must be in the same directory - adb_server_ip (str) – The IP address of the ADB server
- adb_server_port (int) – The port for the ADB server
- device_class (str) – The type of device:
'auto'
(detect whether it is an Android TV or Fire TV device),'androidtv'
, or'firetv'`
Returns: aftv – The representation of the device
Return type: - host (str) – The address of the device in the format
androidtv
is a Python 3 package that provides state information and control of Android TV and Fire TV devices via ADB. This package is used by the Android TV integration in Home Assistant.
Acknowledgments¶
This is based on python-firetv by happyleavesaoc and the androidtv component for Home Assistant by a1ex4, and it depends on python-adb and pure-python-adb.