Skip to content

Commit

Permalink
Merge branch 'rc-stable7-019' into color-with-hue-saturation
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 authored Jan 12, 2025
2 parents 1b5f1ab + fbaf2c4 commit 2ae04c6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
52 changes: 31 additions & 21 deletions Classes/WebServer/WebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,8 @@ def rest_zDevice(self, verb, data, parameters):
if attribut == "Battery" and attribut in self.ListOfDevices[item]:
if self.ListOfDevices[item]["Battery"] in ( {}, ) and "IASBattery" in self.ListOfDevices[item]:
device[attribut] = str(self.ListOfDevices[item][ "IASBattery" ])
elif isinstance( self.ListOfDevices[item]["Battery"], int):
device[attribut] = self.ListOfDevices[item]["Battery"]
elif isinstance( self.ListOfDevices[item]["Battery"], (int,float)):
device[attribut] = int(self.ListOfDevices[item]["Battery"])
device["BatteryInside"] = True

elif item == "CheckParam":
Expand Down Expand Up @@ -1530,43 +1530,53 @@ def rest_zigate_mode(self, verb, data, parameters):
_response["Data"] = json.dumps("ZiGate mode: %s requested" % mode)
return _response


def rest_battery_state(self, verb, data, parameters):
_response = prepResponseMessage(self, setupHeadersResponse())
_response["Headers"]["Content-Type"] = "application/json; charset=utf-8"
if verb == "GET":
_battEnv = {"Battery":{"<30%":{}, "<50%": {}, ">50%" : {}},"Update Time":{ "Unknown": {}, "< 1 week": {}, "> 1 week": {}}}
for x in self.ListOfDevices:
self.logging("Debug", f"rest_battery_state - {x}")
if x == "0000":
continue
continue

if self.ListOfDevices[x]["ZDeviceName"] == "":
_deviceName = x
else:
_deviceName = self.ListOfDevices[x]["ZDeviceName"]
battery = self.ListOfDevices[x].get("Battery")

if "Battery" in self.ListOfDevices[x] and isinstance(self.ListOfDevices[x]["Battery"], int):
if self.ListOfDevices[x]["Battery"] > 50:
_battEnv["Battery"][">50%"][_deviceName] = {"Battery": self.ListOfDevices[x]["Battery"]}
if battery is None:
continue
self.logging("Debug", f"rest_battery_state - {x} Battery found")

elif self.ListOfDevices[x]["Battery"] > 30:
_battEnv["Battery"]["<50%"][_deviceName] = {"Battery": self.ListOfDevices[x]["Battery"]}
_deviceName = self.ListOfDevices[x].get("ZDeviceName", x )

else:
_battEnv["Battery"]["<30%"][_deviceName] = {"Battery": self.ListOfDevices[x]["Battery"]}
if not isinstance( battery, (int, float)):
self.logging("Debug", f"rest_battery_state - {x} Battery found, but not int !! {type(battery)}")
continue
battery = int(battery)

if "BatteryUpdateTime" in self.ListOfDevices[x]:
if (int(time.time()) - self.ListOfDevices[x]["BatteryUpdateTime"]) > 604800: # one week in seconds
_battEnv["Update Time"]["> 1 week"][_deviceName] = {"BatteryUpdateTime": self.ListOfDevices[x]["BatteryUpdateTime"]}
if self.ListOfDevices[x]["Battery"] > 50:
_battEnv["Battery"][">50%"][_deviceName] = {"Battery": battery}

else:
_battEnv["Update Time"]["< 1 week"][_deviceName] = {"BatteryUpdateTime": self.ListOfDevices[x]["BatteryUpdateTime"]}
elif self.ListOfDevices[x]["Battery"] > 30:
_battEnv["Battery"]["<50%"][_deviceName] = {"Battery": battery}

else:
_battEnv["Battery"]["<30%"][_deviceName] = {"Battery": battery}

if "BatteryUpdateTime" in self.ListOfDevices[x]:
if (int(time.time()) - self.ListOfDevices[x]["BatteryUpdateTime"]) > 604800: # one week in seconds
_battEnv["Update Time"]["> 1 week"][_deviceName] = {"BatteryUpdateTime": self.ListOfDevices[x]["BatteryUpdateTime"]}

else:
_battEnv["Update Time"]["Unknown"][_deviceName] = "Unknown"
_battEnv["Update Time"]["< 1 week"][_deviceName] = {"BatteryUpdateTime": self.ListOfDevices[x]["BatteryUpdateTime"]}

else:
_battEnv["Update Time"]["Unknown"][_deviceName] = "Unknown"

self.logging("Debug", f"rest_battery_state - {_battEnv}")
_response["Data"] = json.dumps(_battEnv, sort_keys=True)
return _response

def logging(self, logType, message):
self.log.logging("WebServer", logType, message)

Expand Down
5 changes: 4 additions & 1 deletion Modules/heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
ReadAttributeRequest_0402,
ReadAttributeRequest_0405,
ReadAttributeRequest_0702_0000,
ReadAttributeRequest_0702_0017,
ReadAttributeRequest_0702_PC321,
ReadAttributeRequest_0702_ZLinky_TIC,
ReadAttributeRequest_ff66,
Expand Down Expand Up @@ -344,7 +345,9 @@ def pollingManufSpecificDevices(self, NwkId, HB):
"HumiPollingFreq": ReadAttributeRequest_0405,
"BattPollingFreq": ReadAttributeRequest_0001,
"ZLinkyIndexes": ReadAttributeReq_Scheduled_ZLinky, # Based on a specific time
"ZLinkyPollingPTEC": ReadAttributeReq_Scheduled_ZLinky # Every 15' by default
"ZLinkyPollingPTEC": ReadAttributeReq_Scheduled_ZLinky, # Every 15' by default
"InletTempPolling": ReadAttributeRequest_0702_0017, # Retreive Inlet Temperature

}

if "Param" not in self.ListOfDevices[NwkId]:
Expand Down
10 changes: 10 additions & 0 deletions Modules/readAttributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,16 @@ def ReadAttributeRequest_0702_0000(self, key):
self.log.logging("ReadAttributes", "Debug", "Request Summation on 0x0702 cluster: " + key + " EPout = " + EPout, nwkid=key)
ReadAttributeReq(self, key, ZIGATE_EP, EPout, "0702", listAttributes, ackIsDisabled=is_ack_tobe_disabled(self, key))


def ReadAttributeRequest_0702_0017(self, key):
# Cluster 0x0702 Metering / Specific 0x0017 (Device Temperature)
ListOfEp = getListOfEpForCluster(self, key, "0702")
for EPout in ListOfEp:
listAttributes = [0x0017]
self.log.logging("ReadAttributes", "Debug", "Request InletTemperature on 0x0702 cluster: " + key + " EPout = " + EPout, nwkid=key)
ReadAttributeReq(self, key, ZIGATE_EP, EPout, "0702", listAttributes, ackIsDisabled=is_ack_tobe_disabled(self, key))


def ReadAttributeRequest_0702_multiplier_divisor(self, key):
ListOfEp = getListOfEpForCluster(self, key, "0702")
for EPout in ListOfEp:
Expand Down
4 changes: 4 additions & 0 deletions Modules/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def getListOfEpForCluster(self, NwkId, SearchCluster):

oldFashion = ( "ClusterType" in self.ListOfDevices[NwkId] and self.ListOfDevices[NwkId]["ClusterType"] not in ({}, "") )
for Ep in list(self.ListOfDevices[NwkId]["Ep"].keys()):
# check that is not a Fake Ep
if is_fake_ep(self, NwkId, Ep):
continue

if SearchCluster not in self.ListOfDevices[NwkId]["Ep"][Ep]:
continue

Expand Down

0 comments on commit 2ae04c6

Please sign in to comment.