Replace rfxtrx entity events with integration events (#37565)

* Drop per entity events

* Correct linting error

* Drop keys()
This commit is contained in:
Joakim Plate authored and GitHub committed 2020-07-13 02:57:19 +02:00
1 parent d3b47b6d89
commit 87f6b7cdd4
14 files changed
+132 -183

No files matched your search

+8 -14
View File
@@ -2,18 +2,15 @@
import logging
from homeassistant.components.cover import CoverEntity
from homeassistant.const import ATTR_STATE, CONF_DEVICES, STATE_OPEN
from homeassistant.const import CONF_DEVICES, STATE_OPEN
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,
)
@@ -46,18 +43,18 @@ 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 = RfxtrxCover(event.device, datas, entity_info[CONF_SIGNAL_REPETITIONS])
entity = RfxtrxCover(
event.device, device_id, entity_info[CONF_SIGNAL_REPETITIONS]
)
entities.append(entity)
add_entities(entities)
def cover_update(event):
def cover_update(event, device_id):
"""Handle cover 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)
@@ -70,9 +67,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"".join(f"{x:02x}" for x in event.data),
)
datas = {ATTR_STATE: False, ATTR_FIRE_EVENT: False}
entity = RfxtrxCover(
event.device, datas, DEFAULT_SIGNAL_REPETITIONS, event=event
event.device, device_id, DEFAULT_SIGNAL_REPETITIONS, event=event
)
add_entities([entity])
@@ -127,13 +123,11 @@ class RfxtrxCover(RfxtrxDevice, CoverEntity, RestoreEntity):
elif event.values["Command"] in COMMAND_OFF_LIST:
self._state = False
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"])