1 """Support for the DIRECTV remote."""
3 from __future__
import annotations
5 from collections.abc
import Iterable
6 from datetime
import timedelta
10 from directv
import DIRECTV, DIRECTVError
17 from .const
import DOMAIN
18 from .entity
import DIRECTVEntity
20 _LOGGER = logging.getLogger(__name__)
28 async_add_entities: AddEntitiesCallback,
30 """Load DirecTV remote based on a config entry."""
31 dtv = hass.data[DOMAIN][entry.entry_id]
37 name=str.title(location.name),
38 address=location.address,
40 for location
in dtv.device.locations
47 """Device that sends commands to a DirecTV receiver."""
49 def __init__(self, *, dtv: DIRECTV, name: str, address: str =
"0") ->
None:
50 """Initialize DirecTV remote."""
62 """Update device state."""
63 status = await self.
dtvdtv.status(self.
_address_address)
65 if status
in (
"active",
"standby"):
73 """Turn the device on."""
74 await self.
dtvdtv.remote(
"poweron", self.
_address_address)
77 """Turn the device off."""
78 await self.
dtvdtv.remote(
"poweroff", self.
_address_address)
81 """Send a command to a device.
83 Supported keys: power, poweron, poweroff, format,
84 pause, rew, replay, stop, advance, ffwd, record,
85 play, guide, active, list, exit, back, menu, info,
86 up, down, left, right, select, red, green, yellow,
87 blue, chanup, chandown, prev, 0, 1, 2, 3, 4, 5,
88 6, 7, 8, 9, dash, enter
90 num_repeats = kwargs[ATTR_NUM_REPEATS]
92 for _
in range(num_repeats):
93 for single_command
in command:
95 await self.
dtvdtv.remote(single_command, self.
_address_address)
98 "Sending command %s to device %s failed",
None async_turn_off(self, **Any kwargs)
None async_send_command(self, Iterable[str] command, **Any kwargs)
None __init__(self, *DIRECTV dtv, str name, str address="0")
None async_turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)