mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Add channel-mapping for HomeMatic (#31178)
* Update entity.py * Fix Black * Fix Black * Update entity.py * Use new style python * Simplify * Allow multible attribute with different channels * Black Co-authored-by: Pascal Vizeli <pascal.vizeli@syshack.ch>
This commit is contained in:
parent
bcdef4e500
commit
9902b648fb
@ -40,6 +40,7 @@ class HMDevice(Entity):
|
|||||||
self._hmdevice = None
|
self._hmdevice = None
|
||||||
self._connected = False
|
self._connected = False
|
||||||
self._available = False
|
self._available = False
|
||||||
|
self._channel_map = set()
|
||||||
|
|
||||||
# Set parameter to uppercase
|
# Set parameter to uppercase
|
||||||
if self._state:
|
if self._state:
|
||||||
@ -110,15 +111,12 @@ class HMDevice(Entity):
|
|||||||
|
|
||||||
def _hm_event_callback(self, device, caller, attribute, value):
|
def _hm_event_callback(self, device, caller, attribute, value):
|
||||||
"""Handle all pyhomematic device events."""
|
"""Handle all pyhomematic device events."""
|
||||||
_LOGGER.debug("%s received event '%s' value: %s", self._name, attribute, value)
|
|
||||||
has_changed = False
|
has_changed = False
|
||||||
|
|
||||||
# Is data needed for this instance?
|
# Is data needed for this instance?
|
||||||
if attribute in self._data:
|
if f"{attribute}:{device.partition(':')[2]}" in self._channel_map:
|
||||||
# Did data change?
|
self._data[attribute] = value
|
||||||
if self._data[attribute] != value:
|
has_changed = True
|
||||||
self._data[attribute] = value
|
|
||||||
has_changed = True
|
|
||||||
|
|
||||||
# Availability has changed
|
# Availability has changed
|
||||||
if self.available != (not self._hmdevice.UNREACH):
|
if self.available != (not self._hmdevice.UNREACH):
|
||||||
@ -131,9 +129,6 @@ 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."""
|
||||||
channels_to_sub = set()
|
|
||||||
|
|
||||||
# Push data to channels_to_sub from hmdevice metadata
|
|
||||||
for metadata in (
|
for metadata in (
|
||||||
self._hmdevice.SENSORNODE,
|
self._hmdevice.SENSORNODE,
|
||||||
self._hmdevice.BINARYNODE,
|
self._hmdevice.BINARYNODE,
|
||||||
@ -150,19 +145,11 @@ class HMDevice(Entity):
|
|||||||
channel = channels[0]
|
channel = channels[0]
|
||||||
else:
|
else:
|
||||||
channel = self._channel
|
channel = self._channel
|
||||||
|
# Remember the channel for this attribute to ignore invalid events later
|
||||||
# Prepare for subscription
|
self._channel_map.add(f"{node}:{channel!s}")
|
||||||
try:
|
|
||||||
channels_to_sub.add(int(channel))
|
|
||||||
except (ValueError, TypeError):
|
|
||||||
_LOGGER.error("Invalid channel in metadata from %s", self._name)
|
|
||||||
|
|
||||||
# Set callbacks
|
# Set callbacks
|
||||||
for channel in channels_to_sub:
|
self._hmdevice.setEventCallback(callback=self._hm_event_callback, bequeath=True)
|
||||||
_LOGGER.debug("Subscribe channel %d from %s", channel, self._name)
|
|
||||||
self._hmdevice.setEventCallback(
|
|
||||||
callback=self._hm_event_callback, bequeath=False, channel=channel
|
|
||||||
)
|
|
||||||
|
|
||||||
def _load_data_from_hm(self):
|
def _load_data_from_hm(self):
|
||||||
"""Load first value from pyhomematic."""
|
"""Load first value from pyhomematic."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user