Home Assistant Unofficial Reference 2024.12.1
remote.py
Go to the documentation of this file.
1 """Home Assistant integration to control a sky box using the remote platform."""
2 
3 from collections.abc import Iterable
4 import logging
5 from typing import Any
6 
7 from skyboxremote import VALID_KEYS, RemoteControl
8 
9 from homeassistant.components.remote import RemoteEntity
10 from homeassistant.core import HomeAssistant
11 from homeassistant.exceptions import ServiceValidationError
12 from homeassistant.helpers.device_registry import DeviceInfo
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 
15 from . import SkyRemoteConfigEntry
16 from .const import DOMAIN
17 
18 _LOGGER = logging.getLogger(__name__)
19 
20 
22  hass: HomeAssistant,
23  config: SkyRemoteConfigEntry,
24  async_add_entities: AddEntitiesCallback,
25 ) -> None:
26  """Set up the Sky remote platform."""
28  [SkyRemote(config.runtime_data, config.entry_id)],
29  True,
30  )
31 
32 
34  """Representation of a Sky Remote."""
35 
36  _attr_has_entity_name = True
37  _attr_name = None
38 
39  def __init__(self, remote: RemoteControl, unique_id: str) -> None:
40  """Initialize the Sky Remote."""
41  self._remote_remote = remote
42  self._attr_unique_id_attr_unique_id = unique_id
43  self._attr_device_info_attr_device_info = DeviceInfo(
44  identifiers={(DOMAIN, unique_id)},
45  manufacturer="SKY",
46  model="Sky Box",
47  name=remote.host,
48  )
49 
50  def turn_on(self, activity: str | None = None, **kwargs: Any) -> None:
51  """Send the power on command."""
52  self.send_commandsend_commandsend_command(["sky"])
53 
54  def turn_off(self, activity: str | None = None, **kwargs: Any) -> None:
55  """Send the power command."""
56  self.send_commandsend_commandsend_command(["power"])
57 
58  def send_command(self, command: Iterable[str], **kwargs: Any) -> None:
59  """Send a list of commands to the device."""
60  for cmd in command:
61  if cmd not in VALID_KEYS:
63  f"{cmd} is not in Valid Keys: {VALID_KEYS}"
64  )
65  try:
66  self._remote_remote.send_keys(command)
67  except ValueError as err:
68  _LOGGER.error("Invalid command: %s. Error: %s", command, err)
69  return
70  _LOGGER.debug("Successfully sent command %s", command)
None send_command(self, Iterable[str] command, **Any kwargs)
Definition: __init__.py:227
None send_command(self, Iterable[str] command, **Any kwargs)
Definition: remote.py:58
None __init__(self, RemoteControl remote, str unique_id)
Definition: remote.py:39
None turn_on(self, str|None activity=None, **Any kwargs)
Definition: remote.py:50
None turn_off(self, str|None activity=None, **Any kwargs)
Definition: remote.py:54
None async_setup_entry(HomeAssistant hass, SkyRemoteConfigEntry config, AddEntitiesCallback async_add_entities)
Definition: remote.py:25