1 """Remote control support for Android TV Remote."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
23 from .
import AndroidTVRemoteConfigEntry
24 from .const
import CONF_APP_NAME
25 from .entity
import AndroidTVRemoteBaseEntity
32 config_entry: AndroidTVRemoteConfigEntry,
33 async_add_entities: AddEntitiesCallback,
35 """Set up the Android TV remote entity based on a config entry."""
36 api = config_entry.runtime_data
41 """Android TV Remote Entity."""
43 _attr_supported_features = RemoteEntityFeature.ACTIVITY
46 """Update current app info."""
48 self._apps[current_app].
get(CONF_APP_NAME, current_app)
49 if current_app
in self._apps
55 """Update the state when the current app changes."""
60 """Register callbacks."""
64 app.get(CONF_APP_NAME,
"")
for app
in self._apps.values()
70 """Remove callbacks."""
76 """Turn the Android TV on."""
77 if not self.
is_onis_on:
79 activity = kwargs.get(ATTR_ACTIVITY,
"")
84 for app_id, app
in self._apps.items()
85 if app.get(CONF_APP_NAME,
"") == activity
92 """Turn the Android TV off."""
97 """Send commands to one device."""
98 num_repeats = kwargs.get(ATTR_NUM_REPEATS, DEFAULT_NUM_REPEATS)
99 delay_secs = kwargs.get(ATTR_DELAY_SECS, DEFAULT_DELAY_SECS)
100 hold_secs = kwargs.get(ATTR_HOLD_SECS, DEFAULT_HOLD_SECS)
102 for _
in range(num_repeats):
103 for single_command
in command:
106 await asyncio.sleep(hold_secs)
110 await asyncio.sleep(delay_secs)
None _send_key_command(self, str key_code, str direction="SHORT")
None _send_launch_app_command(self, str app_link)
None async_will_remove_from_hass(self)
None _current_app_updated(self, str current_app)
None async_turn_on(self, **Any kwargs)
None async_added_to_hass(self)
None _update_current_app(self, str current_app)
None async_turn_off(self, **Any kwargs)
None async_send_command(self, Iterable[str] command, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, AndroidTVRemoteConfigEntry config_entry, AddEntitiesCallback async_add_entities)
web.Response get(self, web.Request request, str config_key)