Skip to content

Commit

Permalink
fix, output device_power only if battery key is present
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmotea committed Mar 10, 2023
1 parent 808477a commit 0429b6c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions BridgeEmulator/HueObjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,21 +1836,23 @@ def getButtons(self):
return result

def getDevicePower(self):
result = {
"id": str(uuid.uuid5(
uuid.NAMESPACE_URL, self.id_v2 + 'device_power')),
"id_v1": "/sensors/" + self.id_v1,
"owner": {
"rid": self.id_v2,
"rtype": "device"
},
"power_state": {},
"type": "device_power"
}
if "battery" in self.config and self.config["battery"]:
result["power_state"].update({"battery_level": self.config["battery"],
"battery_state": "normal"
})
result = None
if "battery" in self.config:
result = {
"id": str(uuid.uuid5(
uuid.NAMESPACE_URL, self.id_v2 + 'device_power')),
"id_v1": "/sensors/" + self.id_v1,
"owner": {
"rid": self.id_v2,
"rtype": "device"
},
"power_state": {},
"type": "device_power"
}
if self.config["battery"]:
result["power_state"].update({"battery_level": self.config["battery"],
"battery_state": "normal"
})
return result

def update_attr(self, newdata):
Expand Down

0 comments on commit 0429b6c

Please sign in to comment.