Prioritize channels for homematic event subscriptions ()

* Prioritize SENSORNODE for event callbacks

* Ran black

* Use lazy % formatting for logging

Co-authored-by: Franck Nijhof <git@frenck.dev>
pull/68905/head
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
1 changed files with 10 additions and 8 deletions
homeassistant/components/homematic

View File

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