From 116ebd18ac7494a3d3a09f9375deb96441c006fd Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Mon, 13 Jan 2025 14:23:53 +0100 Subject: [PATCH] update and fix --- DevicesModules/custom_zlinky.py | 10 +++++----- Modules/zlinky.py | 26 +++++++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/DevicesModules/custom_zlinky.py b/DevicesModules/custom_zlinky.py index ffa237036..85fb66cb7 100644 --- a/DevicesModules/custom_zlinky.py +++ b/DevicesModules/custom_zlinky.py @@ -79,11 +79,10 @@ def zlinky_set_color_based_on_counter(self, domoticz_devices, nwkid, ep, cluster """ def update_color(nwkid, previous_color, new_color): """Update the device color if it has changed.""" - if new_color != previous_color: - self.log.logging("ZLinky", "Status", f"Updating ZLinky color from {previous_color} to {new_color}", nwkid) - MajDomoDevice(self, domoticz_devices, nwkid, "01", "0009", new_color, Attribute_="0020") - zlinky_color_tarif(self, nwkid, new_color) - ReadAttributeReq_Scheduled_ZLinky(self, nwkid) + self.log.logging("ZLinky", "Status", f"Updating ZLinky color from {previous_color} to {new_color}", nwkid) + MajDomoDevice(self, domoticz_devices, nwkid, "01", "0009", new_color, Attribute_="0020") + zlinky_color_tarif(self, nwkid, new_color) + ReadAttributeReq_Scheduled_ZLinky(self, nwkid) def get_new_color(attribut, op_tarifiare): """Determine the new color based on the attribute and tariff type.""" @@ -157,6 +156,7 @@ def handle_attribut_value(attribut, store_keys=None, update_color=False, totaliz MajDomoDevice(self, domoticz_devices, nwkid, maj_ep, cluster, str(value), Attribute_=attribut) if attribut == "0020": + MajDomoDevice(self, domoticz_devices, nwkid, "01", "0009", value, Attribute_="0020") zlinky_color_tarif(self, nwkid, str(value)) if update_color: diff --git a/Modules/zlinky.py b/Modules/zlinky.py index e0751aa94..af6ace3da 100644 --- a/Modules/zlinky.py +++ b/Modules/zlinky.py @@ -102,17 +102,17 @@ def convert_kva_to_ampere( kva ): return ( kva * 1000) / 200 + def zlinky_color_tarif(self, MsgSrcAddr, color): - if "ZLinky" not in self.ListOfDevices[MsgSrcAddr]: - self.ListOfDevices[MsgSrcAddr]["ZLinky"] = {} - self.ListOfDevices[MsgSrcAddr]["ZLinky"]["Color"] = color + self.ListOfDevices.setdefault(MsgSrcAddr, {}).setdefault("ZLinky", {})["Color"] = color -def store_ZLinky_infos( self, nwkid, command_tic, value): +def store_ZLinky_infos( self, nwkid, command_tic, value): if 'ZLinky' not in self.ListOfDevices[ nwkid ]: self.ListOfDevices[ nwkid ][ 'ZLinky' ] = {} self.ListOfDevices[ nwkid ][ 'ZLinky' ][ command_tic ] = value + def get_ISOUSC( self, nwkid ): if ( @@ -155,12 +155,20 @@ def get_OPTARIF( self, nwkid): return "BASE" -def get_instant_power( self, nwkid ): - return round(float(self.ListOfDevices[nwkid]["Ep"]["01"]["0b04"]["050f"]), 2) if "0b04" in self.ListOfDevices[nwkid]["Ep"]["01"] and "050f" in self.ListOfDevices[nwkid]["Ep"]["01"]["0b04"] else 0 +def get_instant_power(self, nwkid): + try: + device = self.ListOfDevices.get(nwkid, {}) + ep = device.get("Ep", {}).get("01", {}) + cluster = ep.get("0b04", {}) + power = cluster.get("050f") + return round(float(power), 2) if power is not None else 0 + except (ValueError, TypeError): + return 0 + + +def get_tarif_color(self, nwkid): + return self.ListOfDevices.get(nwkid, {}).get("ZLinky", {}).get("Color") -def get_tarif_color( self, nwkid ): - return self.ListOfDevices[nwkid]["ZLinky"]["Color"] if "ZLinky" in self.ListOfDevices[nwkid] and "Color" in self.ListOfDevices[nwkid]["ZLinky"] else None - def zlinky_check_alarm(self, Devices, MsgSrcAddr, MsgSrcEp, value):