From 94fde3bf238bb9fe122d0567e5bad2b462a4cf8e Mon Sep 17 00:00:00 2001 From: Sven Naumann Date: Wed, 30 Mar 2022 16:28:23 +0200 Subject: [PATCH] Prioritize channels for homematic event subscriptions (#56619) * Prioritize SENSORNODE for event callbacks * Ran black * Use lazy % formatting for logging Co-authored-by: Franck Nijhof --- homeassistant/components/homematic/entity.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/homematic/entity.py b/homeassistant/components/homematic/entity.py index 8e83484505b5..1fe3799bbd92 100644 --- a/homeassistant/components/homematic/entity.py +++ b/homeassistant/components/homematic/entity.py @@ -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)