1 """Support for RFXtrx switches."""
3 from __future__
import annotations
8 import RFXtrx
as rfxtrxmod
17 from .
import DeviceTuple, async_setup_platform_entry, get_pt2262_cmd
22 DEVICE_PACKET_TYPE_LIGHTING4,
25 from .entity
import RfxtrxCommandEntity
27 DATA_SWITCH = f
"{DOMAIN}_switch"
29 _LOGGER = logging.getLogger(__name__)
32 def supported(event: rfxtrxmod.RFXtrxEvent) -> bool:
33 """Return whether an event supports switch."""
35 isinstance(event.device, rfxtrxmod.LightingDevice)
36 and not event.device.known_to_be_dimmable
37 and not event.device.known_to_be_rollershutter
38 or isinstance(event.device, rfxtrxmod.RfyDevice)
44 config_entry: ConfigEntry,
45 async_add_entities: AddEntitiesCallback,
47 """Set up config entry."""
50 event: rfxtrxmod.RFXtrxEvent,
51 auto: rfxtrxmod.RFXtrxEvent |
None,
52 device_id: DeviceTuple,
53 entity_info: dict[str, Any],
59 entity_info.get(CONF_DATA_BITS),
60 entity_info.get(CONF_COMMAND_ON),
61 entity_info.get(CONF_COMMAND_OFF),
62 event=event
if auto
else None,
67 hass, config_entry, async_add_entities, supported, _constructor
72 """Representation of a RFXtrx switch."""
76 device: rfxtrxmod.RFXtrxDevice,
77 device_id: DeviceTuple,
78 data_bits: int |
None =
None,
79 cmd_on: int |
None =
None,
80 cmd_off: int |
None =
None,
81 event: rfxtrxmod.RFXtrxEvent |
None =
None,
83 """Initialize the RFXtrx switch."""
84 super().
__init__(device, device_id, event=event)
90 """Restore device state."""
93 if self.
_event_event
is None:
95 if old_state
is not None:
99 """Apply event for a lighting 4 device."""
103 cmd =
int(cmdstr, 16)
112 assert isinstance(event, rfxtrxmod.ControlEvent)
113 if event.values[
"Command"]
in COMMAND_ON_LIST:
115 elif event.values[
"Command"]
in COMMAND_OFF_LIST:
119 """Apply command from rfxtrx."""
121 if event.device.packettype == DEVICE_PACKET_TYPE_LIGHTING4:
128 self, event: rfxtrxmod.RFXtrxEvent, device_id: DeviceTuple
130 """Check if event applies to me and update."""
137 """Turn the device on."""
138 if self.
_cmd_on_cmd_on
is not None:
139 await self._async_send(self.
_device_device.send_command, self.
_cmd_on_cmd_on)
141 await self._async_send(self.
_device_device.send_on)
146 """Turn the device off."""
147 if self.
_cmd_off_cmd_off
is not None:
148 await self._async_send(self.
_device_device.send_command, self.
_cmd_off_cmd_off)
150 await self._async_send(self.
_device_device.send_off)
None _apply_event(self, rfxtrxmod.RFXtrxEvent event)
bool _event_applies(self, rfxtrxmod.RFXtrxEvent event, DeviceTuple device_id)
None _apply_event(self, rfxtrxmod.RFXtrxEvent event)
None _handle_event(self, rfxtrxmod.RFXtrxEvent event, DeviceTuple device_id)
None _apply_event_lighting4(self, rfxtrxmod.RFXtrxEvent event)
None async_turn_on(self, **Any kwargs)
None _apply_event_standard(self, rfxtrxmod.RFXtrxEvent event)
None async_turn_off(self, **Any kwargs)
None __init__(self, rfxtrxmod.RFXtrxDevice device, DeviceTuple device_id, int|None data_bits=None, int|None cmd_on=None, int|None cmd_off=None, rfxtrxmod.RFXtrxEvent|None event=None)
None async_added_to_hass(self)
None async_write_ha_state(self)
State|None async_get_last_state(self)
bool supported(rfxtrxmod.RFXtrxEvent event)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
str|None get_pt2262_cmd(str device_id, int data_bits)
None async_setup_platform_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities, Callable[[rfxtrxmod.RFXtrxEvent], bool] supported, Callable[[rfxtrxmod.RFXtrxEvent, rfxtrxmod.RFXtrxEvent|None, DeviceTuple, dict[str, Any],], list[Entity],] constructor)