1 """Support for RFXtrx lights."""
3 from __future__
import annotations
8 import RFXtrx
as rfxtrxmod
17 from .
import DeviceTuple, async_setup_platform_entry
18 from .const
import COMMAND_OFF_LIST, COMMAND_ON_LIST
19 from .entity
import RfxtrxCommandEntity
21 _LOGGER = logging.getLogger(__name__)
24 def supported(event: rfxtrxmod.RFXtrxEvent) -> bool:
25 """Return whether an event supports light."""
27 isinstance(event.device, rfxtrxmod.LightingDevice)
28 and event.device.known_to_be_dimmable
34 config_entry: ConfigEntry,
35 async_add_entities: AddEntitiesCallback,
37 """Set up config entry."""
40 event: rfxtrxmod.RFXtrxEvent,
41 auto: rfxtrxmod.RFXtrxEvent |
None,
42 device_id: DeviceTuple,
43 entity_info: dict[str, Any],
49 event=event
if auto
else None,
54 hass, config_entry, async_add_entities, supported, _constructor
59 """Representation of a RFXtrx light."""
61 _attr_color_mode = ColorMode.BRIGHTNESS
62 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
63 _attr_brightness: int = 0
64 _device: rfxtrxmod.LightingDevice
67 """Restore RFXtrx device state (ON/OFF)."""
70 if self.
_event_event
is None:
72 if old_state
is not None:
74 if brightness := old_state.attributes.get(ATTR_BRIGHTNESS):
78 """Turn the device on."""
79 brightness = kwargs.get(ATTR_BRIGHTNESS)
81 if brightness
is None:
82 await self._async_send(self.
_device_device.send_on)
85 await self._async_send(self.
_device_device.send_dim, brightness * 100 // 255)
91 """Turn the device off."""
92 await self._async_send(self.
_device_device.send_off)
97 def _apply_event(self, event: rfxtrxmod.RFXtrxEvent) ->
None:
98 """Apply command from rfxtrx."""
99 assert isinstance(event, rfxtrxmod.ControlEvent)
101 if event.values[
"Command"]
in COMMAND_ON_LIST:
103 elif event.values[
"Command"]
in COMMAND_OFF_LIST:
105 elif event.values[
"Command"] ==
"Set level":
106 brightness = event.values[
"Dim level"] * 255 // 100
112 self, event: rfxtrxmod.RFXtrxEvent, device_id: DeviceTuple
114 """Check if event applies to me and update."""
None _apply_event(self, rfxtrxmod.RFXtrxEvent event)
None _handle_event(self, rfxtrxmod.RFXtrxEvent event, DeviceTuple device_id)
None async_added_to_hass(self)
None async_write_ha_state(self)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
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)
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)