diff --git a/homeassistant/components/homematic/entity.py b/homeassistant/components/homematic/entity.py index 4ed893bbf14..54811c3ccdf 100644 --- a/homeassistant/components/homematic/entity.py +++ b/homeassistant/components/homematic/entity.py @@ -40,6 +40,7 @@ class HMDevice(Entity): self._hmdevice = None self._connected = False self._available = False + self._channel_map = set() # Set parameter to uppercase if self._state: @@ -110,15 +111,12 @@ class HMDevice(Entity): def _hm_event_callback(self, device, caller, attribute, value): """Handle all pyhomematic device events.""" - _LOGGER.debug("%s received event '%s' value: %s", self._name, attribute, value) has_changed = False # Is data needed for this instance? - if attribute in self._data: - # Did data change? - if self._data[attribute] != value: - self._data[attribute] = value - has_changed = True + if f"{attribute}:{device.partition(':')[2]}" in self._channel_map: + self._data[attribute] = value + has_changed = True # Availability has changed if self.available != (not self._hmdevice.UNREACH): @@ -131,9 +129,6 @@ class HMDevice(Entity): def _subscribe_homematic_events(self): """Subscribe all required events to handle job.""" - channels_to_sub = set() - - # Push data to channels_to_sub from hmdevice metadata for metadata in ( self._hmdevice.SENSORNODE, self._hmdevice.BINARYNODE, @@ -150,19 +145,11 @@ class HMDevice(Entity): channel = channels[0] else: channel = self._channel - - # Prepare for subscription - try: - channels_to_sub.add(int(channel)) - except (ValueError, TypeError): - _LOGGER.error("Invalid channel in metadata from %s", self._name) + # Remember the channel for this attribute to ignore invalid events later + self._channel_map.add(f"{node}:{channel!s}") # Set callbacks - for channel in channels_to_sub: - _LOGGER.debug("Subscribe channel %d from %s", channel, self._name) - self._hmdevice.setEventCallback( - callback=self._hm_event_callback, bequeath=False, channel=channel - ) + self._hmdevice.setEventCallback(callback=self._hm_event_callback, bequeath=True) def _load_data_from_hm(self): """Load first value from pyhomematic."""