From 0ae08575c0151438de0bc9a038e5ecad71708b61 Mon Sep 17 00:00:00 2001 From: Pipiche <8291674+pipiche38@users.noreply.github.com> Date: Sat, 9 Dec 2023 16:51:19 +0100 Subject: [PATCH] Device/remote legrand toggle (#1679) Remote Switch seems to communicate also on Cluster 000f/f000 --- Modules/domoMaj.py | 23 +++++++++++++---------- Modules/readZclClusters.py | 33 +++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Modules/domoMaj.py b/Modules/domoMaj.py index 841524939..fd1b9a76e 100644 --- a/Modules/domoMaj.py +++ b/Modules/domoMaj.py @@ -1169,17 +1169,20 @@ def MajDomoDevice(self, Devices, NWKID, Ep, clusterID, value, Attribute_="", Col self.log.logging("Widget", "Debug", "------> Switch off as System Mode is Off") UpdateDevice_v2(self, Devices, DeviceUnit, 0, "00", BatteryLevel, SignalLevel) - elif WidgetType in SWITCH_SELECTORS and value in SWITCH_SELECTORS[WidgetType]: - self.log.logging("Widget", "Debug", "------> Auto Update %s" % str(SWITCH_SELECTORS[WidgetType][value])) - if len(SWITCH_SELECTORS[WidgetType][value]) == 2: - nValue, sValue = SWITCH_SELECTORS[WidgetType][value] - _ForceUpdate = SWITCH_SELECTORS[WidgetType]["ForceUpdate"] - self.log.logging( "Widget", "Debug", "------> Switch update WidgetType: %s with %s" % ( - WidgetType, str(SWITCH_SELECTORS[WidgetType])), NWKID, ) - UpdateDevice_v2(self, Devices, DeviceUnit, nValue, sValue, BatteryLevel, SignalLevel, ForceUpdate_=_ForceUpdate) + else: + if WidgetType in SWITCH_SELECTORS and value in SWITCH_SELECTORS[WidgetType]: + self.log.logging("Widget", "Debug", "------> Auto Update %s" % str(SWITCH_SELECTORS[WidgetType][value])) + if len(SWITCH_SELECTORS[WidgetType][value]) == 2: + nValue, sValue = SWITCH_SELECTORS[WidgetType][value] + _ForceUpdate = SWITCH_SELECTORS[WidgetType]["ForceUpdate"] + self.log.logging( "Widget", "Debug", "------> Switch update WidgetType: %s with %s" % ( + WidgetType, str(SWITCH_SELECTORS[WidgetType])), NWKID, ) + UpdateDevice_v2(self, Devices, DeviceUnit, nValue, sValue, BatteryLevel, SignalLevel, ForceUpdate_=_ForceUpdate) + else: + self.log.logging( "Widget", "Error", "------> len(SWITCH_SELECTORS[ %s ][ %s ]) == %s" % ( + WidgetType, value, len(SWITCH_SELECTORS[WidgetType])), NWKID, ) else: - self.log.logging( "Widget", "Error", "------> len(SWITCH_SELECTORS[ %s ][ %s ]) == %s" % ( - WidgetType, value, len(SWITCH_SELECTORS[WidgetType])), NWKID, ) + self.log.logging("Widget", "Error", "------> Auto Update (%s %s) not found in SWITCH_SELECTORS" % ( WidgetType, value)) if "WindowCovering" in ClusterType: # 0x0102 if WidgetType in ("VenetianInverted", "Venetian", "Vanne", "VanneInverted", "WindowCovering", "Curtain", "CurtainInverted", "Blind"): diff --git a/Modules/readZclClusters.py b/Modules/readZclClusters.py index 4b2a369c5..f060bae99 100644 --- a/Modules/readZclClusters.py +++ b/Modules/readZclClusters.py @@ -353,32 +353,37 @@ def cluster_attribute_retrieval(self, ep, cluster, attribute, parameter, model=N def action_majdomodevice( self, Devices, MsgSrcAddr, MsgSrcEp, MsgClusterId, MsgAttrID, device_model, value ): + + DOMO_DEVICE_FORMATER = { + "str": str, + "str_2digits": lambda x: "%02d" % int(x), + "str_4digits": lambda x: "%04d" % int(x), + "strhex": lambda x: "%x" % x, + "str2hex": lambda x: "%02x" % x, + "str4hex": lambda x: "%04x" % x + } + self.log.logging( "ZclClusters", "Debug", "action_majdomodevice - %s/%s %s %s %s %s" %( - MsgSrcAddr, MsgSrcEp, MsgClusterId, MsgAttrID, device_model, value )) + MsgSrcAddr, MsgSrcEp, MsgClusterId, MsgAttrID, device_model, value )) + _majdomo_formater = cluster_attribute_retrieval( self, MsgSrcEp, MsgClusterId, MsgAttrID, "DomoDeviceFormat", model=device_model) self.log.logging( "ZclClusters", "Debug", " _majdomo_formater: %s" %_majdomo_formater) - + if get_device_config_param( self, MsgSrcAddr, "disableBinaryInputCluster") and MsgClusterId == "000f": return - - majValue = value - if _majdomo_formater: - if _majdomo_formater == "str": - majValue = str( value ) - elif _majdomo_formater == "strhex": - majValue = "%x" %value - + majValue = DOMO_DEVICE_FORMATER[ _majdomo_formater ](value) if (_majdomo_formater and _majdomo_formater in DOMO_DEVICE_FORMATER) else value + self.log.logging( "ZclClusters", "Debug", " _majdomo_formater: %s %s -> %s" %(_majdomo_formater, value, majValue)) + _majdomo_cluster = cluster_attribute_retrieval( self, MsgSrcEp, MsgClusterId, MsgAttrID, "UpdDomoDeviceWithCluster", model=device_model) self.log.logging( "ZclClusters", "Debug", " _majdomo_cluster: %s" %_majdomo_cluster) - + majCluster = _majdomo_cluster if _majdomo_cluster is not None else MsgClusterId _majdomo_attribute = cluster_attribute_retrieval( self, MsgSrcEp, MsgClusterId, MsgAttrID, "UpdDomoDeviceWithAttribute", model=device_model) - self.log.logging( "ZclClusters", "Debug", " _majdomo_attribute: %s" %_majdomo_attribute) - majAttribute = _majdomo_attribute if _majdomo_attribute is not None else "" - + self.log.logging( "ZclClusters", "Debug", " _majdomo_attribute: %s -> %s" %(_majdomo_attribute, majAttribute)) + MajDomoDevice(self, Devices, MsgSrcAddr, MsgSrcEp, majCluster, majValue, Attribute_=majAttribute)