Skip to content

Commit

Permalink
Improve device merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Mat931 committed Jan 3, 2024
1 parent aae518a commit b0dc9b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions custom_components/digitalstrom/api/apartment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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"]

Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion custom_components/digitalstrom/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"manufacturer": "aizo ag"
}
],
"version": "0.0.4",
"version": "0.0.6",
"zeroconf": ["_dssweb._tcp.local."]
}

0 comments on commit b0dc9b0

Please sign in to comment.