1
mirror of https://github.com/home-assistant/core synced 2024-09-09 12:51:22 +02:00

Prioritize channels for homematic event subscriptions (#56619)

* Prioritize SENSORNODE for event callbacks

* Ran black

* Use lazy % formatting for logging

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Sven Naumann 2022-03-30 16:28:23 +02:00 committed by GitHub
parent ca1337d9c2
commit 94fde3bf23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,7 +50,7 @@ class HMDevice(Entity):
self._data: dict[str, str] = {}
self._connected = False
self._available = False
self._channel_map: set[str] = set()
self._channel_map: dict[str, str] = {}
if entity_description is not None:
self.entity_description = entity_description
@ -127,7 +127,7 @@ class HMDevice(Entity):
has_changed = False
# Is data needed for this instance?
if f"{attribute}:{device.partition(':')[2]}" in self._channel_map:
if device.partition(":")[2] == self._channel_map.get(attribute):
self._data[attribute] = value
has_changed = True
@ -143,12 +143,12 @@ class HMDevice(Entity):
def _subscribe_homematic_events(self):
"""Subscribe all required events to handle job."""
for metadata in (
self._hmdevice.SENSORNODE,
self._hmdevice.BINARYNODE,
self._hmdevice.ATTRIBUTENODE,
self._hmdevice.WRITENODE,
self._hmdevice.EVENTNODE,
self._hmdevice.ACTIONNODE,
self._hmdevice.EVENTNODE,
self._hmdevice.WRITENODE,
self._hmdevice.ATTRIBUTENODE,
self._hmdevice.BINARYNODE,
self._hmdevice.SENSORNODE,
):
for node, channels in metadata.items():
# Data is needed for this instance
@ -159,7 +159,9 @@ class HMDevice(Entity):
else:
channel = self._channel
# Remember the channel for this attribute to ignore invalid events later
self._channel_map.add(f"{node}:{channel!s}")
self._channel_map[node] = str(channel)
_LOGGER.debug("Channel map for %s: %s", self._address, str(self._channel_map))
# Set callbacks
self._hmdevice.setEventCallback(callback=self._hm_event_callback, bequeath=True)