Home Assistant Unofficial Reference 2024.12.1
remote.py
Go to the documentation of this file.
1 """Support for the SamsungTV remote."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Iterable
6 from typing import Any
7 
8 from homeassistant.components.remote import ATTR_NUM_REPEATS, RemoteEntity
9 from homeassistant.core import HomeAssistant, callback
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from . import SamsungTVConfigEntry
13 from .const import LOGGER
14 from .entity import SamsungTVEntity
15 
16 
18  hass: HomeAssistant,
19  entry: SamsungTVConfigEntry,
20  async_add_entities: AddEntitiesCallback,
21 ) -> None:
22  """Set up the Samsung TV from a config entry."""
23  coordinator = entry.runtime_data
24  async_add_entities([SamsungTVRemote(coordinator=coordinator)])
25 
26 
28  """Device that sends commands to a SamsungTV."""
29 
30  _attr_name = None
31 
32  @callback
33  def _handle_coordinator_update(self) -> None:
34  """Handle data update."""
35  self._attr_is_on_attr_is_on = self.coordinator.is_on
36  self.async_write_ha_stateasync_write_ha_state()
37 
38  async def async_turn_off(self, **kwargs: Any) -> None:
39  """Turn the device off."""
40  await super()._async_turn_off()
41 
42  async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None:
43  """Send a command to a device.
44 
45  Supported keys vary between models.
46  See https://github.com/jaruba/ha-samsungtv-tizen/blob/master/Key_codes.md
47  """
48  if self._bridge_bridge.power_off_in_progress:
49  LOGGER.debug("TV is powering off, not sending keys: %s", command)
50  return
51 
52  num_repeats = kwargs[ATTR_NUM_REPEATS]
53  command_list = list(command)
54 
55  for _ in range(num_repeats):
56  await self._bridge_bridge.async_send_keys(command_list)
57 
58  async def async_turn_on(self, **kwargs: Any) -> None:
59  """Turn the remote on."""
60  await super()._async_turn_on()
None async_send_command(self, Iterable[str] command, **Any kwargs)
Definition: remote.py:42
None async_setup_entry(HomeAssistant hass, SamsungTVConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: remote.py:21