Replace rfxtrx entity events with integration events (#37565)
* Drop per entity events * Correct linting error * Drop keys()
This commit is contained in:
1 parent
d3b47b6d89
commit
87f6b7cdd4
14 files changed
+132
-183
No files matched your search
@@ -8,18 +8,15 @@ from homeassistant.components.light import (
|
||||
SUPPORT_BRIGHTNESS,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.const import ATTR_STATE, CONF_DEVICES, STATE_ON
|
||||
from homeassistant.const import CONF_DEVICES, STATE_ON
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from . import (
|
||||
ATTR_FIRE_EVENT,
|
||||
CONF_AUTOMATIC_ADD,
|
||||
CONF_FIRE_EVENT,
|
||||
CONF_SIGNAL_REPETITIONS,
|
||||
DEFAULT_SIGNAL_REPETITIONS,
|
||||
SIGNAL_EVENT,
|
||||
RfxtrxDevice,
|
||||
fire_command_event,
|
||||
get_device_id,
|
||||
get_rfx_object,
|
||||
)
|
||||
@@ -58,19 +55,19 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
continue
|
||||
device_ids.add(device_id)
|
||||
|
||||
datas = {ATTR_STATE: None, ATTR_FIRE_EVENT: entity_info[CONF_FIRE_EVENT]}
|
||||
entity = RfxtrxLight(event.device, datas, entity_info[CONF_SIGNAL_REPETITIONS])
|
||||
entity = RfxtrxLight(
|
||||
event.device, device_id, entity_info[CONF_SIGNAL_REPETITIONS]
|
||||
)
|
||||
|
||||
entities.append(entity)
|
||||
|
||||
add_entities(entities)
|
||||
|
||||
def light_update(event):
|
||||
def light_update(event, device_id):
|
||||
"""Handle light updates from the RFXtrx gateway."""
|
||||
if not supported(event):
|
||||
return
|
||||
|
||||
device_id = get_device_id(event.device)
|
||||
if device_id in device_ids:
|
||||
return
|
||||
device_ids.add(device_id)
|
||||
@@ -83,9 +80,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"".join(f"{x:02x}" for x in event.data),
|
||||
)
|
||||
|
||||
datas = {ATTR_STATE: None, ATTR_FIRE_EVENT: False}
|
||||
entity = RfxtrxLight(
|
||||
event.device, datas, DEFAULT_SIGNAL_REPETITIONS, event=event
|
||||
event.device, device_id, DEFAULT_SIGNAL_REPETITIONS, event=event
|
||||
)
|
||||
|
||||
add_entities([entity])
|
||||
@@ -157,13 +153,11 @@ class RfxtrxLight(RfxtrxDevice, LightEntity, RestoreEntity):
|
||||
self._brightness = event.values["Dim level"] * 255 // 100
|
||||
self._state = self._brightness > 0
|
||||
|
||||
def _handle_event(self, event):
|
||||
def _handle_event(self, event, device_id):
|
||||
"""Check if event applies to me and update."""
|
||||
if event.device.id_string != self._device.id_string:
|
||||
if device_id != self._device_id:
|
||||
return
|
||||
|
||||
self._apply_event(event)
|
||||
|
||||
self.schedule_update_ha_state()
|
||||
if self.should_fire_event:
|
||||
fire_command_event(self.hass, self.entity_id, event.values["Command"])
|
||||
Reference in new issue
Block a user