From b0dc9b0f814a2443e200a988014130251188f6ee Mon Sep 17 00:00:00 2001 From: Mat931 <49403702+Mat931@users.noreply.github.com> Date: Wed, 3 Jan 2024 14:00:36 +0100 Subject: [PATCH] Improve device merging --- .../digitalstrom/api/apartment.py | 24 ++++++++++++++++--- custom_components/digitalstrom/manifest.json | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/custom_components/digitalstrom/api/apartment.py b/custom_components/digitalstrom/api/apartment.py index 229ead8..84b38b6 100644 --- a/custom_components/digitalstrom/api/apartment.py +++ b/custom_components/digitalstrom/api/apartment.py @@ -91,7 +91,9 @@ def __init__(self, client: DigitalstromClient, apartment, dsuid: str): self.binary_inputs = {} self.output_channels = {} self.button = None - self.meter = None + self.meter_dsuid = None + self.dsuid_index = None + self.oem_part_number = None self.parent_device = None self.available = False self.availability_callbacks = [] @@ -142,6 +144,12 @@ def _load_general(self, data): if meter_dsuid := data.get("meterDSUID"): self.meter_dsuid = meter_dsuid + if "dSUIDIndex" in data.keys(): + self.dsuid_index = data["dSUIDIndex"] + + if "OemPartNumber" in data.keys(): + self.oem_part_number = data["OemPartNumber"] + if "isPresent" in data.keys(): self.available = data["isPresent"] @@ -308,11 +316,21 @@ def find_split_devices(self): for prev, curr in zip(devices, devices[1:]): if ( int(curr.dsuid, 16) <= int(prev.dsuid, 16) + 0x100 - and prev.meter == curr.meter + and prev.meter_dsuid == curr.meter_dsuid + and ( + curr.dsuid_index != 0 + or (curr.oem_part_number not in [0, 1]) + or not ( + prev.dsuid_index == curr.dsuid_index + and prev.oem_part_number == curr.oem_part_number + ) + ) ): - curr.parent_device = ( + parent_device = ( prev if prev.parent_device is None else prev.parent_device ) + curr.parent_device = parent_device + self.logger.debug(f"Merging devices {parent_device.dsuid} {curr.dsuid}") async def get_devices(self): data = await self.client.request("apartment/getDevices") diff --git a/custom_components/digitalstrom/manifest.json b/custom_components/digitalstrom/manifest.json index 81f40ff..d83cd69 100644 --- a/custom_components/digitalstrom/manifest.json +++ b/custom_components/digitalstrom/manifest.json @@ -20,6 +20,6 @@ "manufacturer": "aizo ag" } ], - "version": "0.0.4", + "version": "0.0.6", "zeroconf": ["_dssweb._tcp.local."] }