1 """Support for the AndroidTV remote."""
3 from __future__
import annotations
5 from collections.abc
import Iterable
9 from androidtv.constants
import KEYS
17 from .const
import CONF_TURN_OFF_COMMAND, CONF_TURN_ON_COMMAND, DOMAIN
18 from .entity
import AndroidTVEntity, adb_decorator
20 _LOGGER = logging.getLogger(__name__)
24 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
26 """Set up the AndroidTV remote from a config entry."""
31 """Device that sends commands to a AndroidTV."""
34 _attr_should_poll =
False
38 """Turn on the device."""
40 if turn_on_cmd := options.get(CONF_TURN_ON_COMMAND):
41 await self.
aftvaftv.adb_shell(turn_on_cmd)
47 """Turn off the device."""
49 if turn_off_cmd := options.get(CONF_TURN_OFF_COMMAND):
50 await self.
aftvaftv.adb_shell(turn_off_cmd)
56 """Send a command to a device."""
58 num_repeats = kwargs[ATTR_NUM_REPEATS]
61 if key := KEYS.get(cmd):
62 command_list.append(f
"input keyevent {key}")
64 command_list.append(cmd)
66 for _
in range(num_repeats):
67 for cmd
in command_list:
69 await self.
aftvaftv.adb_shell(cmd)
70 except UnicodeDecodeError
as ex:
72 translation_domain=DOMAIN,
73 translation_key=
"failed_send",
74 translation_placeholders={
"cmd": cmd},
None async_send_command(self, Iterable[str] command, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)