Home Assistant Unofficial Reference 2024.12.1
remote.py
Go to the documentation of this file.
1 """Support for madVR remote control."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Iterable
6 import logging
7 from typing import Any
8 
9 from homeassistant.components.remote import RemoteEntity
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.entity_platform import AddEntitiesCallback
12 
13 from . import MadVRConfigEntry
14 from .coordinator import MadVRCoordinator
15 from .entity import MadVREntity
16 
17 _LOGGER = logging.getLogger(__name__)
18 
19 
21  hass: HomeAssistant,
22  entry: MadVRConfigEntry,
23  async_add_entities: AddEntitiesCallback,
24 ) -> None:
25  """Set up the madVR remote."""
26  coordinator = entry.runtime_data
28  [
29  MadvrRemote(coordinator),
30  ]
31  )
32 
33 
35  """Remote entity for the madVR integration."""
36 
37  _attr_name = None
38 
39  def __init__(
40  self,
41  coordinator: MadVRCoordinator,
42  ) -> None:
43  """Initialize the remote entity."""
44  super().__init__(coordinator)
45  self.madvr_clientmadvr_client = coordinator.client
46  self._attr_unique_id_attr_unique_id = coordinator.mac
47 
48  @property
49  def is_on(self) -> bool:
50  """Return true if the device is on."""
51  return self.madvr_clientmadvr_client.is_on
52 
53  async def async_turn_off(self, **kwargs: Any) -> None:
54  """Turn off the device."""
55  _LOGGER.debug("Turning off")
56  try:
57  await self.madvr_clientmadvr_client.power_off()
58  except (ConnectionError, NotImplementedError) as err:
59  _LOGGER.error("Failed to turn off device %s", err)
60 
61  async def async_turn_on(self, **kwargs: Any) -> None:
62  """Turn on the device."""
63  _LOGGER.debug("Turning on device")
64 
65  try:
66  await self.madvr_clientmadvr_client.power_on(mac=self.coordinator.mac)
67  except (ConnectionError, NotImplementedError) as err:
68  _LOGGER.error("Failed to turn on device %s", err)
69 
70  async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None:
71  """Send a command to one device."""
72  _LOGGER.debug("adding command %s", command)
73  try:
74  await self.madvr_clientmadvr_client.add_command_to_queue(command)
75  except (ConnectionError, NotImplementedError) as err:
76  _LOGGER.error("Failed to send command %s", err)
None async_turn_on(self, **Any kwargs)
Definition: remote.py:61
None __init__(self, MadVRCoordinator coordinator)
Definition: remote.py:42
None async_send_command(self, Iterable[str] command, **Any kwargs)
Definition: remote.py:70
None async_turn_off(self, **Any kwargs)
Definition: remote.py:53
None async_setup_entry(HomeAssistant hass, MadVRConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: remote.py:24