From c1a3156a92dc970acaf27c76238ace18a35c6be1 Mon Sep 17 00:00:00 2001 From: Patrick Pichon Date: Wed, 29 Nov 2023 21:43:52 +0100 Subject: [PATCH] several fixes to make it working --- Modules/domoMaj.py | 52 ++++++++++++++------------------ Modules/domoTools.py | 6 ++-- Modules/domoticzAbstractLayer.py | 38 +++++++++++++---------- 3 files changed, 47 insertions(+), 49 deletions(-) diff --git a/Modules/domoMaj.py b/Modules/domoMaj.py index c3a03275d..2f4ad2d7b 100644 --- a/Modules/domoMaj.py +++ b/Modules/domoMaj.py @@ -288,12 +288,7 @@ def MajDomoDevice(self, Devices, NWKID, Ep, clusterID, value, Attribute_="", Col self.log.logging("Widget", "Debug", "------> P1Meter : %s (%s)" % (value, type(value)), NWKID) # P1Meter report Instant and Cummulative Power. # We need to retreive the Cummulative Power. - _, CurrentsValue, _, _, _, _ = retrieve_data_from_current(self, Devices, device_id_ieee, DeviceUnit, "0;0;0;0;0;0") - - if len(CurrentsValue.split(";")) != 6: - # First time after device creation - CurrentsValue = "0;0;0;0;0;0" - cur_usage1, cur_usage2, cur_return1, cur_return2, _, _ = CurrentsValue.split(";") + cur_usage1, cur_usage2, cur_return1, cur_return2, _, _ = retrieve_data_from_current(self, Devices, device_id_ieee, DeviceUnit, "0;0;0;0;0;0") usage1 = usage2 = return1 = return2 = cons = prod = 0 @@ -829,11 +824,10 @@ def MajDomoDevice(self, Devices, NWKID, Ep, clusterID, value, Attribute_="", Col self.log.logging("Widget", "Error", "Error while trying to get Adjusted Value for Temp %s %s %s %s" % ( NWKID, value, WidgetType, e), NWKID) - CurrentnValue, CurrentsValue, _, _, _ = retrieve_data_from_current(self, Devices, device_id_ieee, DeviceUnit, "0;0;0;0;0") + current_temp, current_humi, current_hum_stat, current_baro, current_baro_forecast = retrieve_data_from_current(self, Devices, device_id_ieee, DeviceUnit, "0;0;0;0;0") - self.log.logging("Widget", "Debug", f"------> Adj Value: {adjvalue} from: {value} to {value + adjvalue} [{CurrentsValue}]", NWKID) + self.log.logging("Widget", "Debug", f"------> Adj Value: {adjvalue} from: {value} to {value + adjvalue} [{current_temp}, {current_humi}, {current_hum_stat}, {current_baro}, {current_baro_forecast}]", NWKID) - SplitData = CurrentsValue.split(";") NewNvalue = 0 NewSvalue = "" @@ -841,23 +835,23 @@ def MajDomoDevice(self, Devices, NWKID, Ep, clusterID, value, Attribute_="", Col NewNvalue = round(value + adjvalue, 1) NewSvalue = str(NewNvalue) - elif WidgetType == "Temp+Hum" and len(SplitData) >= 2: - NewSvalue = f"{round(value + adjvalue, 1)};{SplitData[1]};{SplitData[2]}" + elif WidgetType == "Temp+Hum": + NewSvalue = f"{round(value + adjvalue, 1)};{current_humi};{current_hum_stat}" - elif WidgetType == "Temp+Hum+Baro" and len(SplitData) >= 4: - NewSvalue = f"{round(value + adjvalue, 1)};{SplitData[1]};{SplitData[2]};{SplitData[3]};{SplitData[4]}" + elif WidgetType == "Temp+Hum+Baro": + NewSvalue = f"{round(value + adjvalue, 1)};{current_humi};{current_hum_stat};{current_baro};{current_baro_forecast}" self.log.logging("Widget", "Debug", f"------> {WidgetType} update: {NewNvalue} - {NewSvalue}") UpdateDevice_v2(self, Devices, DeviceUnit, NewNvalue, NewSvalue, BatteryLevel, SignalLevel) if ClusterType == "Humi" and WidgetType in ("Humi", "Temp+Hum", "Temp+Hum+Baro"): - self.log.logging("Widget", "Debug", f"------> Humi: {value}, WidgetType: {WidgetType}", NWKID) - CurrentnValue, CurrentsValue, _, _, _ = retrieve_data_from_current(self, Devices, device_id_ieee, DeviceUnit, "0;0;0;0;0") - SplitData = CurrentsValue.split(";") + self.log.logging("Widget", "Debug", f"------> Humi: {value}, WidgetType: {WidgetType}", NWKID) + NewNvalue = 0 NewSvalue = "" humi_status = calculate_humidity_status(value) + current_temp, current_humi, current_hum_stat, current_baro, current_baro_forecast = retrieve_data_from_current(self, Devices, device_id_ieee, DeviceUnit, "0;0;0;0;0") if WidgetType == "Humi": NewNvalue = value @@ -865,13 +859,13 @@ def MajDomoDevice(self, Devices, NWKID, Ep, clusterID, value, Attribute_="", Col self.log.logging("Widget", "Debug", f"------> Humi update: {NewNvalue} - {NewSvalue}") UpdateDevice_v2(self, Devices, DeviceUnit, NewNvalue, NewSvalue, BatteryLevel, SignalLevel) - elif WidgetType == "Temp+Hum" and len(SplitData) >= 2: - NewSvalue = f"{SplitData[0]};{value};{humi_status}" + elif WidgetType == "Temp+Hum": + NewSvalue = f"{current_temp};{value};{humi_status}" self.log.logging("Widget", "Debug", f"------> Temp+Hum update: {NewNvalue} - {NewSvalue}") UpdateDevice_v2(self, Devices, DeviceUnit, NewNvalue, NewSvalue, BatteryLevel, SignalLevel) - elif WidgetType == "Temp+Hum+Baro" and len(SplitData) >= 4: - NewSvalue = f"{SplitData[0]};{value};{humi_status};{SplitData[3]};{SplitData[4]}" + elif WidgetType == "Temp+Hum+Baro": + NewSvalue = f"{current_temp};{value};{humi_status};{current_baro};{current_baro_forecast}" self.log.logging("Widget", "Debug", f"------> Temp+Hum+Baro update: {NewNvalue} - {NewSvalue}") UpdateDevice_v2(self, Devices, DeviceUnit, NewNvalue, NewSvalue, BatteryLevel, SignalLevel) @@ -888,18 +882,16 @@ def MajDomoDevice(self, Devices, NWKID, Ep, clusterID, value, Attribute_="", Col baroValue = round(value + adjvalue, 1) self.log.logging("Widget", "Debug", f"------> Adj Value: {adjvalue} from: {value} to {baroValue}", NWKID) - CurrentnValue, CurrentsValue, _, _, _ = retrieve_data_from_current(self, Devices, device_id_ieee, DeviceUnit, "0;0;0;0;0") - - SplitData = CurrentsValue.split(";") NewNvalue = 0 NewSvalue = "" - + Bar_forecast = calculate_baro_forecast(baroValue) + current_temp, current_humi, current_hum_stat, current_baro, current_baro_forecast = retrieve_data_from_current(self, Devices, device_id_ieee, DeviceUnit, "0;0;0;0;0") if WidgetType == "Baro": NewSvalue = f"{baroValue};{Bar_forecast}" elif WidgetType == "Temp+Hum+Baro": - NewSvalue = f"{SplitData[0]};{SplitData[1]};{SplitData[2]};{baroValue};{Bar_forecast}" + NewSvalue = f"{current_temp};{current_humi};{current_hum_stat};{baroValue};{Bar_forecast}" UpdateDevice_v2(self, Devices, DeviceUnit, NewNvalue, NewSvalue, BatteryLevel, SignalLevel) @@ -1569,14 +1561,14 @@ def retrieve_data_from_current(self, Devices, DeviceID, Unit, _format): _, current_svalue = domo_read_nValue_sValue(self, Devices, DeviceID, Unit) nb_parameters = len(_format.split(";")) - currents_values = current_svalue.split(";") + current_list_values = current_svalue.split(";") - if len(currents_values) != nb_parameters: - currents_values = ["0"] * nb_parameters + if len(current_list_values) != nb_parameters: + current_list_values = ["0"] * nb_parameters - self.log.logging("Widget", "Debug", f"retrieve_data_from_current - Nb Param: {nb_parameters} returning {currents_values}") + self.log.logging("Widget", "Log", f"retrieve_data_from_current - Nb Param: {nb_parameters} returning {current_list_values}") - return current_svalue + return current_list_values def normalized_lvl_value( self, Devices, DeviceID, DeviceUnit, value ): diff --git a/Modules/domoTools.py b/Modules/domoTools.py index 2ca35d816..69ad33d2c 100644 --- a/Modules/domoTools.py +++ b/Modules/domoTools.py @@ -275,7 +275,7 @@ def UpdateDevice_v2(self, Devices, Unit, nValue, sValue, BatteryLvl, SignalLvl, Devices[Unit].DeviceID, str(self.IEEE2NWK)) ) return - self.log.logging( "Widget", "Debug", "UpdateDevice_v2 %s:%s:%s %3s:%3s:%5s (%15s)" % ( + self.log.logging( "Widget", "Log", "UpdateDevice_v2 %s:%s:%s %3s:%3s:%5s (%15s)" % ( nValue, sValue, Color_, BatteryLvl, SignalLvl, ForceUpdate_, Devices[Unit].Name), self.IEEE2NWK[Devices[Unit].DeviceID], ) # Make sure that the Domoticz device still exists (they can be deleted) before updating it @@ -289,7 +289,7 @@ def UpdateDevice_v2(self, Devices, Unit, nValue, sValue, BatteryLvl, SignalLvl, or ForceUpdate_ or Devices[Unit].BatteryLevel != int(BatteryLvl) or Devices[Unit].TimedOut - ): + ): DeviceID_ = None # This is required when we will use The Extended Framework if ( @@ -297,7 +297,7 @@ def UpdateDevice_v2(self, Devices, Unit, nValue, sValue, BatteryLvl, SignalLvl, and ForceUpdate_ and (Devices[Unit].nValue == int(nValue)) and (Devices[Unit].sValue == sValue) - ): + ): # Due to new version of Domoticz which do not log in case we Update the same value nReset = 0 diff --git a/Modules/domoticzAbstractLayer.py b/Modules/domoticzAbstractLayer.py index 065e451cd..2b170875b 100644 --- a/Modules/domoticzAbstractLayer.py +++ b/Modules/domoticzAbstractLayer.py @@ -252,7 +252,7 @@ def domo_update_api(self, Devices, DeviceID_, Unit_, nValue, sValue, SignalLevel TimedOut (int, optional): Timeoud flag 0 to unset the Timeout. Defaults to None. Color (str, optional): Color . Defaults to "". """ - self.log.logging("AbstractDz", "Debug", "domo_update_api: %s %s %s %s %s %s %s %s %s" %( + self.log.logging("AbstractDz", "Log", "domo_update_api: DeviceID_ : %s Unit_: %s nValue: %s sValue: %s SignalLevel: %s BatteryLevel: %s TimedOut: %s Color: %s : %s" %( DeviceID_, Unit_, nValue, sValue, SignalLevel, BatteryLevel, TimedOut, Color, Options)) if DOMOTICZ_EXTENDED_API: @@ -281,20 +281,26 @@ def domo_update_api(self, Devices, DeviceID_, Unit_, nValue, sValue, SignalLevel return # Legacy + # Define common update parameters + update_params = { + 'nValue': int(nValue), + 'sValue': str(sValue), + } + if SignalLevel is not None: + update_params['SignalLevel'] = int(SignalLevel) + if BatteryLevel is not None: + update_params['BatteryLevel'] = int(BatteryLevel) if TimedOut is not None: - Devices[Unit_].Update(nValue=nValue, sValue=sValue, TimedOut=TimedOut,) - - elif Options is not None: - Devices[Unit_].Update(nValue=nValue, sValue=sValue, Options=Options,) - - elif SignalLevel is None and BatteryLevel is None: - Devices[Unit_].Update(nValue=nValue, sValue=sValue, TimedOut=0,) - - elif Color != "": - Devices[Unit_].Update( nValue=int(nValue), sValue=str(sValue), Color=Color, SignalLevel=int(SignalLevel), BatteryLevel=int(BatteryLevel), TimedOut=0, ) - - else: - Devices[Unit_].Update( nValue=int(nValue), sValue=str(sValue), SignalLevel=int(SignalLevel), BatteryLevel=int(BatteryLevel), TimedOut=0, ) + update_params['TimedOut'] = TimedOut + if Options is not None: + update_params['Options'] = Options + if Color != "": + update_params['Color'] = Color + + # Perform the update with the defined parameters + self.log.logging("AbstractDz", "Log", "domo_update_api: update_params %s" %(update_params)) + + Devices[Unit_].Update(**update_params) def domo_read_nValue_sValue(self, Devices, DeviceID, Unit): @@ -363,7 +369,7 @@ def _is_device_tobe_switched_off(self, Devices,DeviceID_, Unit_): ) def device_touch_api(self, Devices, DeviceId_, Unit_): - self.log.logging("AbstractDz", "Debug", f"device_touch: {DeviceId_} {Unit_}") + #self.log.logging("AbstractDz", "Debug", f"device_touch: {DeviceId_} {Unit_}") # In case of Meter Device (kWh), we must not touch it, otherwise it will destroy the metering # Type, Subtype, SwitchType @@ -384,7 +390,7 @@ def device_touch_api(self, Devices, DeviceId_, Unit_): # Last Touch was done more than 30 seconds ago. Devices[DeviceId_].Units[Unit_].Touch() if DOMOTICZ_EXTENDED_API else Devices[Unit_].Touch() return - self.log.logging("AbstractDz", "Debug", f"device_touch too early: {DeviceId_} {Unit_}") + #self.log.logging("AbstractDz", "Debug", f"device_touch too early: {DeviceId_} {Unit_}") def timeout_widget_api(self, Devices, DeviceId_, Unit_, timeout_value):