1 """Base entity for Android TV Remote."""
3 from __future__
import annotations
7 from androidtvremote2
import AndroidTVRemote, ConnectionClosed
16 from .const
import CONF_APPS, DOMAIN
20 """Android TV Remote Base Entity."""
23 _attr_has_entity_name =
True
24 _attr_should_poll =
False
26 def __init__(self, api: AndroidTVRemote, config_entry: ConfigEntry) ->
None:
27 """Initialize the entity."""
29 self.
_host_host = config_entry.data[CONF_HOST]
30 self.
_name_name = config_entry.data[CONF_NAME]
31 self._apps: dict[str, Any] = config_entry.options.get(CONF_APPS, {})
34 device_info = api.device_info
35 assert config_entry.unique_id
38 connections={(CONNECTION_NETWORK_MAC, config_entry.data[CONF_MAC])},
39 identifiers={(DOMAIN, config_entry.unique_id)},
41 manufacturer=device_info[
"manufacturer"],
42 model=device_info[
"model"],
47 """Update the state when the device is ready to receive commands or is unavailable."""
53 """Update the state when device turns on or off."""
58 """Register callbacks."""
63 """Remove callbacks."""
68 """Send a key press to Android TV.
70 This does not block; it buffers the data and arranges for it to be sent out asynchronously.
73 self.
_api_api.send_key_command(key_code, direction)
74 except ConnectionClosed
as exc:
76 "Connection to Android TV device is closed"
80 """Launch an app on Android TV.
82 This does not block; it buffers the data and arranges for it to be sent out asynchronously.
85 self.
_api_api.send_launch_app_command(app_link)
86 except ConnectionClosed
as exc:
88 "Connection to Android TV device is closed"
None async_added_to_hass(self)
None _is_on_updated(self, bool is_on)
None _send_key_command(self, str key_code, str direction="SHORT")
None _is_available_updated(self, bool is_available)
None __init__(self, AndroidTVRemote api, ConfigEntry config_entry)
None _send_launch_app_command(self, str app_link)
None async_will_remove_from_hass(self)
None async_write_ha_state(self)