1 """Support MySensors IR transceivers."""
3 from __future__
import annotations
5 from collections.abc
import Iterable
6 from typing
import Any, cast
19 from .
import setup_mysensors_platform
20 from .const
import MYSENSORS_DISCOVERY, DiscoveryInfo
21 from .entity
import MySensorsChildEntity
22 from .helpers
import on_unload
27 config_entry: ConfigEntry,
28 async_add_entities: AddEntitiesCallback,
30 """Set up this platform for a specific ConfigEntry(==Gateway)."""
34 """Discover and add a MySensors remote."""
40 async_add_entities=async_add_entities,
45 config_entry.entry_id,
48 MYSENSORS_DISCOVERY.format(config_entry.entry_id, Platform.REMOTE),
55 """Representation of a MySensors IR transceiver."""
57 _current_command: str |
None =
None
61 """Return True if remote is on."""
62 set_req = self.gateway.const.SetReq
63 value = cast(str |
None, self.
_child_child.values.get(set_req.V_LIGHT))
70 """Flag supported features."""
72 set_req = self.gateway.const.SetReq
73 if set_req.V_IR_RECORD
in self._values:
74 features = features | RemoteEntityFeature.LEARN_COMMAND
78 """Send commands to a device."""
81 self.gateway.set_child_value(
82 self.node_id, self.child_id, self.value_type, cmd, ack=1
86 """Learn a command from a device."""
87 set_req = self.gateway.const.SetReq
88 commands: list[str] |
None = kwargs.get(ATTR_COMMAND)
90 raise ValueError(
"Command not specified for learn_command service")
92 for command
in commands:
93 self.gateway.set_child_value(
94 self.node_id, self.child_id, set_req.V_IR_RECORD, command, ack=1
98 """Turn the IR transceiver on."""
99 set_req = self.gateway.const.SetReq
101 self.gateway.set_child_value(
108 self.gateway.set_child_value(
109 self.node_id, self.child_id, set_req.V_LIGHT, 1, ack=1
113 """Turn the IR transceiver off."""
114 set_req = self.gateway.const.SetReq
115 self.gateway.set_child_value(
116 self.node_id, self.child_id, set_req.V_LIGHT, 0, ack=1
121 """Update the controller with the latest value from a device."""
124 str |
None, self.
_child_child.values.get(self.value_type)
None async_turn_on(self, **Any kwargs)
None async_send_command(self, Iterable[str] command, **Any kwargs)
None async_learn_command(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
RemoteEntityFeature supported_features(self)
None on_unload(HomeAssistant hass, GatewayId gateway_id, Callable fnct)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None async_discover(DiscoveryInfo discovery_info)
list[MySensorsChildEntity]|None setup_mysensors_platform(HomeAssistant hass, Platform domain, DiscoveryInfo discovery_info, type[MySensorsChildEntity]|Mapping[SensorType, type[MySensorsChildEntity]] device_class,(tuple|None) device_args=None, Callable|None async_add_entities=None)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)