1 """Remote control support for Apple TV."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
19 from .
import LOGGER, PhilipsTVConfigEntry
20 from .coordinator
import PhilipsTVDataUpdateCoordinator
21 from .entity
import PhilipsJsEntity
22 from .helpers
import async_get_turn_on_trigger
27 config_entry: PhilipsTVConfigEntry,
28 async_add_entities: AddEntitiesCallback,
30 """Set up the configuration entry."""
31 coordinator = config_entry.runtime_data
36 """Device that sends commands."""
38 _attr_translation_key =
"remote"
42 coordinator: PhilipsTVDataUpdateCoordinator,
44 """Initialize the Philips TV."""
46 self.
_tv_tv = coordinator.api
51 """Handle being added to hass."""
54 if (entry := self.
registry_entryregistry_entry)
and entry.device_id:
63 """Return true if device is on."""
65 self.
_tv_tv.on
and (self.
_tv_tv.powerstate ==
"On" or self.
_tv_tv.powerstate
is None)
69 """Turn the device on."""
70 if self.
_tv_tv.on
and self.
_tv_tv.powerstate:
71 await self.
_tv_tv.setPowerState(
"On")
77 """Turn the device off."""
79 await self.
_tv_tv.sendKey(
"Standby")
82 LOGGER.debug(
"Tv was already turned off")
85 """Send a command to one device."""
86 num_repeats = kwargs[ATTR_NUM_REPEATS]
87 delay = kwargs.get(ATTR_DELAY_SECS, DEFAULT_DELAY_SECS)
89 for _
in range(num_repeats):
90 for single_command
in command:
91 LOGGER.debug(
"Sending command %s", single_command)
92 await self.
_tv_tv.sendKey(single_command)
93 await asyncio.sleep(delay)
None async_send_command(self, Iterable[str] command, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_added_to_hass(self)
None __init__(self, PhilipsTVDataUpdateCoordinator coordinator)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_register(HomeAssistant hass, system_health.SystemHealthRegistration register)
dict[str, str] async_get_turn_on_trigger(str device_id)
None async_setup_entry(HomeAssistant hass, PhilipsTVConfigEntry config_entry, AddEntitiesCallback async_add_entities)
def async_run(config_dir)