mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Add 'app_name' property and 'apps' config entry to Fire TV (#21601)
* Add 'app_name' property and 'apps' config entry to Fire TV * Define 'CONF_APPS', don't import it * Address reviewer comments
This commit is contained in:
parent
3032283b99
commit
fa938f5628
@ -31,12 +31,14 @@ SUPPORT_FIRETV = SUPPORT_PAUSE | SUPPORT_PLAY | \
|
|||||||
CONF_ADBKEY = 'adbkey'
|
CONF_ADBKEY = 'adbkey'
|
||||||
CONF_ADB_SERVER_IP = 'adb_server_ip'
|
CONF_ADB_SERVER_IP = 'adb_server_ip'
|
||||||
CONF_ADB_SERVER_PORT = 'adb_server_port'
|
CONF_ADB_SERVER_PORT = 'adb_server_port'
|
||||||
|
CONF_APPS = 'apps'
|
||||||
CONF_GET_SOURCES = 'get_sources'
|
CONF_GET_SOURCES = 'get_sources'
|
||||||
|
|
||||||
DEFAULT_NAME = 'Amazon Fire TV'
|
DEFAULT_NAME = 'Amazon Fire TV'
|
||||||
DEFAULT_PORT = 5555
|
DEFAULT_PORT = 5555
|
||||||
DEFAULT_ADB_SERVER_PORT = 5037
|
DEFAULT_ADB_SERVER_PORT = 5037
|
||||||
DEFAULT_GET_SOURCES = True
|
DEFAULT_GET_SOURCES = True
|
||||||
|
DEFAULT_APPS = {}
|
||||||
|
|
||||||
SERVICE_ADB_COMMAND = 'adb_command'
|
SERVICE_ADB_COMMAND = 'adb_command'
|
||||||
|
|
||||||
@ -62,7 +64,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
vol.Optional(CONF_ADB_SERVER_IP): cv.string,
|
vol.Optional(CONF_ADB_SERVER_IP): cv.string,
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_ADB_SERVER_PORT, default=DEFAULT_ADB_SERVER_PORT): cv.port,
|
CONF_ADB_SERVER_PORT, default=DEFAULT_ADB_SERVER_PORT): cv.port,
|
||||||
vol.Optional(CONF_GET_SOURCES, default=DEFAULT_GET_SOURCES): cv.boolean
|
vol.Optional(CONF_GET_SOURCES, default=DEFAULT_GET_SOURCES): cv.boolean,
|
||||||
|
vol.Optional(
|
||||||
|
CONF_APPS, default=DEFAULT_APPS): vol.Schema({cv.string: cv.string})
|
||||||
})
|
})
|
||||||
|
|
||||||
# Translate from `FireTV` reported state to HA state.
|
# Translate from `FireTV` reported state to HA state.
|
||||||
@ -102,11 +106,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
name = config[CONF_NAME]
|
name = config[CONF_NAME]
|
||||||
get_sources = config[CONF_GET_SOURCES]
|
get_sources = config[CONF_GET_SOURCES]
|
||||||
|
apps = config[CONF_APPS]
|
||||||
|
|
||||||
if host in hass.data[FIRETV_DOMAIN]:
|
if host in hass.data[FIRETV_DOMAIN]:
|
||||||
_LOGGER.warning("Platform already setup on %s, skipping", host)
|
_LOGGER.warning("Platform already setup on %s, skipping", host)
|
||||||
else:
|
else:
|
||||||
device = FireTVDevice(ftv, name, get_sources)
|
device = FireTVDevice(ftv, name, get_sources, apps)
|
||||||
add_entities([device])
|
add_entities([device])
|
||||||
_LOGGER.debug("Setup Fire TV at %s%s", host, adb_log)
|
_LOGGER.debug("Setup Fire TV at %s%s", host, adb_log)
|
||||||
hass.data[FIRETV_DOMAIN][host] = device
|
hass.data[FIRETV_DOMAIN][host] = device
|
||||||
@ -161,11 +166,14 @@ def adb_decorator(override_available=False):
|
|||||||
class FireTVDevice(MediaPlayerDevice):
|
class FireTVDevice(MediaPlayerDevice):
|
||||||
"""Representation of an Amazon Fire TV device on the network."""
|
"""Representation of an Amazon Fire TV device on the network."""
|
||||||
|
|
||||||
def __init__(self, ftv, name, get_sources):
|
def __init__(self, ftv, name, get_sources, apps):
|
||||||
"""Initialize the FireTV device."""
|
"""Initialize the FireTV device."""
|
||||||
from firetv import KEYS
|
from firetv import APPS, KEYS
|
||||||
|
self.apps = APPS
|
||||||
self.keys = KEYS
|
self.keys = KEYS
|
||||||
|
|
||||||
|
self.apps.update(apps)
|
||||||
|
|
||||||
self.firetv = ftv
|
self.firetv = ftv
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
@ -222,6 +230,11 @@ class FireTVDevice(MediaPlayerDevice):
|
|||||||
"""Return the current app."""
|
"""Return the current app."""
|
||||||
return self._current_app
|
return self._current_app
|
||||||
|
|
||||||
|
@property
|
||||||
|
def app_name(self):
|
||||||
|
"""Return the friendly name of the current app."""
|
||||||
|
return self.apps.get(self._current_app, self._current_app)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source(self):
|
def source(self):
|
||||||
"""Return the current app."""
|
"""Return the current app."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user