Home Assistant Unofficial Reference 2024.12.1
remote.py
Go to the documentation of this file.
1 """Support for the Roku 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.config_entries import ConfigEntry
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.entity_platform import AddEntitiesCallback
12 
13 from .const import DOMAIN
14 from .coordinator import RokuDataUpdateCoordinator
15 from .entity import RokuEntity
16 from .helpers import roku_exception_handler
17 
18 
20  hass: HomeAssistant,
21  entry: ConfigEntry,
22  async_add_entities: AddEntitiesCallback,
23 ) -> None:
24  """Load Roku remote based on a config entry."""
25  coordinator: RokuDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
26 
28  [
29  RokuRemote(
30  coordinator=coordinator,
31  )
32  ],
33  True,
34  )
35 
36 
38  """Device that sends commands to an Roku."""
39 
40  _attr_name = None
41 
42  @property
43  def is_on(self) -> bool:
44  """Return true if device is on."""
45  return not self.coordinator.data.state.standby
46 
47  @roku_exception_handler()
48  async def async_turn_on(self, **kwargs: Any) -> None:
49  """Turn the device on."""
50  await self.coordinator.roku.remote("poweron")
51  await self.coordinator.async_request_refresh()
52 
53  @roku_exception_handler(ignore_timeout=True)
54  async def async_turn_off(self, **kwargs: Any) -> None:
55  """Turn the device off."""
56  await self.coordinator.roku.remote("poweroff")
57  await self.coordinator.async_request_refresh()
58 
59  @roku_exception_handler()
60  async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None:
61  """Send a command to one device."""
62  num_repeats = kwargs[ATTR_NUM_REPEATS]
63 
64  for _ in range(num_repeats):
65  for single_command in command:
66  await self.coordinator.roku.remote(single_command)
67 
68  await self.coordinator.async_request_refresh()
None async_turn_on(self, **Any kwargs)
Definition: remote.py:48
None async_send_command(self, Iterable[str] command, **Any kwargs)
Definition: remote.py:60
None async_turn_off(self, **Any kwargs)
Definition: remote.py:54
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: remote.py:23