Home Assistant Unofficial Reference 2024.12.1
remote.py
Go to the documentation of this file.
1 """Demo platform that has two fake remotes."""
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 RemoteEntity
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import DEVICE_DEFAULT_NAME
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 
16  hass: HomeAssistant,
17  config_entry: ConfigEntry,
18  async_add_entities: AddEntitiesCallback,
19 ) -> None:
20  """Set up the Demo config entry."""
22  [
23  DemoRemote("Remote One", False),
24  DemoRemote("Remote Two", True),
25  ]
26  )
27 
28 
30  """Representation of a demo remote."""
31 
32  _attr_should_poll = False
33 
34  def __init__(self, name: str | None, state: bool) -> None:
35  """Initialize the Demo Remote."""
36  self._attr_name_attr_name = name or DEVICE_DEFAULT_NAME
37  self._attr_is_on_attr_is_on = state
38  self._last_command_sent_last_command_sent: str | None = None
39 
40  @property
41  def extra_state_attributes(self) -> dict[str, Any] | None:
42  """Return device state attributes."""
43  if self._last_command_sent_last_command_sent is not None:
44  return {"last_command_sent": self._last_command_sent_last_command_sent}
45  return None
46 
47  def turn_on(self, **kwargs: Any) -> None:
48  """Turn the remote on."""
49  self._attr_is_on_attr_is_on = True
50  self.schedule_update_ha_stateschedule_update_ha_state()
51 
52  def turn_off(self, **kwargs: Any) -> None:
53  """Turn the remote off."""
54  self._attr_is_on_attr_is_on = False
55  self.schedule_update_ha_stateschedule_update_ha_state()
56 
57  def send_command(self, command: Iterable[str], **kwargs: Any) -> None:
58  """Send a command to a device."""
59  for com in command:
60  self._last_command_sent_last_command_sent = com
61  self.schedule_update_ha_stateschedule_update_ha_state()
dict[str, Any]|None extra_state_attributes(self)
Definition: remote.py:41
None send_command(self, Iterable[str] command, **Any kwargs)
Definition: remote.py:57
None __init__(self, str|None name, bool state)
Definition: remote.py:34
None schedule_update_ha_state(self, bool force_refresh=False)
Definition: entity.py:1244
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: remote.py:19