Home Assistant Unofficial Reference 2024.12.1
remote.py
Go to the documentation of this file.
1 """Sensor platform for Kaleidescape integration."""
2 
3 from __future__ import annotations
4 
5 from typing import TYPE_CHECKING
6 
7 from kaleidescape import const as kaleidescape_const
8 
9 from homeassistant.components.remote import RemoteEntity
10 from homeassistant.exceptions import HomeAssistantError
11 
12 from .const import DOMAIN as KALEIDESCAPE_DOMAIN
13 from .entity import KaleidescapeEntity
14 
15 if TYPE_CHECKING:
16  from collections.abc import Iterable
17  from typing import Any
18 
19  from homeassistant.config_entries import ConfigEntry
20  from homeassistant.core import HomeAssistant
21  from homeassistant.helpers.entity_platform import AddEntitiesCallback
22 
23 
25  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
26 ) -> None:
27  """Set up the platform from a config entry."""
28  entities = [KaleidescapeRemote(hass.data[KALEIDESCAPE_DOMAIN][entry.entry_id])]
29  async_add_entities(entities)
30 
31 
32 VALID_COMMANDS = {
33  "select",
34  "up",
35  "down",
36  "left",
37  "right",
38  "cancel",
39  "replay",
40  "scan_forward",
41  "scan_reverse",
42  "go_movie_covers",
43  "menu_toggle",
44 }
45 
46 
48  """Representation of a Kaleidescape device."""
49 
50  _attr_name = None
51 
52  @property
53  def is_on(self) -> bool:
54  """Return true if device is on."""
55  return self._device_device.power.state == kaleidescape_const.DEVICE_POWER_STATE_ON
56 
57  async def async_turn_on(self, **kwargs: Any) -> None:
58  """Turn the device on."""
59  await self._device_device.leave_standby()
60 
61  async def async_turn_off(self, **kwargs: Any) -> None:
62  """Turn the device off."""
63  await self._device_device.enter_standby()
64 
65  async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None:
66  """Send a command to a device."""
67  for cmd in command:
68  if cmd not in VALID_COMMANDS:
69  raise HomeAssistantError(f"{cmd} is not a known command")
70  await getattr(self._device_device, cmd)()
None async_send_command(self, Iterable[str] command, **Any kwargs)
Definition: remote.py:65
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: remote.py:26