Skip to content

Commit

Permalink
several fixes to make it working
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Nov 29, 2023
1 parent f98f44c commit c1a3156
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 49 deletions.
52 changes: 22 additions & 30 deletions Modules/domoMaj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -829,49 +824,48 @@ 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 = ""

if WidgetType == "Temp":
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
NewSvalue = str(humi_status)
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)

Expand All @@ -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)

Expand Down Expand Up @@ -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 ):
Expand Down
6 changes: 3 additions & 3 deletions Modules/domoTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -289,15 +289,15 @@ 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 (
self.pluginconf.pluginConf["forceSwitchSelectorPushButton"]
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
Expand Down
38 changes: 22 additions & 16 deletions Modules/domoticzAbstractLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit c1a3156

Please sign in to comment.