Skip to content

Commit

Permalink
Update espDevices.py (diyhue#909)
Browse files Browse the repository at this point in the history
* Update espDevices.py

extend error msg

* Update espDevices.py

extend return msg

* Update espDevices.py

Add args lightlevel, daylight, temperature
  • Loading branch information
hendriksen-mark authored May 12, 2023
1 parent e1bacc7 commit 52dc324
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions BridgeEmulator/flaskUI/espDevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

bridgeConfig = configManager.bridgeConfig.yaml_config


def noMotion(sensor):
bridgeConfig["sensors"][sensor].protocol_cfg["threaded"] = True
logging.info("Monitor the sensor for no motion")
Expand All @@ -26,6 +27,7 @@ def noMotion(sensor):
rulesProcessor(bridgeConfig["sensors"][sensor], current_time)
bridgeConfig["sensors"][sensor].protocol_cfg["threaded"] = False


class Switch(Resource):
def get(self):
args = request.args
Expand Down Expand Up @@ -56,15 +58,24 @@ def get(self):
if "mac" in obj.protocol_cfg:
if obj.protocol_cfg["mac"] == mac:
if obj.type == "ZLLLightLevel":
dark = True if args["dark"] == "true" else False
if obj.state["dark"] != dark:
obj.dxState["dark"] = current_time
obj.state["dark"] = dark
obj.state["lightlevel"] = int(args["lightlevel"])
obj.dxState["lightlevel"] = current_time
dark = True if args["dark"] == "true" else False
daylight = True if args["daylight"] == "true" else False
if obj.state["dark"] != dark:
obj.dxState["dark"] = current_time
obj.state["dark"] = dark
if obj.state["daylight"] != daylight:
obj.dxState["daylight"] = current_time
obj.state["daylight"] = daylight
elif obj.type == "ZLLPresence":
obj.state["presence"] = True
obj.dxState["presence"] = current_time
if obj.protocol_cfg["threaded"] == False:
obj.state["presence"] = True
obj.dxState["presence"] = current_time
if obj.protocol_cfg["threaded"] == False:
Thread(target=noMotion, args=[device]).start()
elif obj.type == "ZLLTemperature":
obj.state["temperature"] = int(args["temperature"])
obj.dxState["temperature"] = current_time
elif obj.type in ["ZLLSwitch", "ZGPSwitch"]:
obj.state["buttonevent"] = int(args["button"])
obj.dxState["buttonevent"] = current_time
Expand All @@ -74,7 +85,8 @@ def get(self):
obj.state["lastupdated"] = datetime.utcnow().strftime(
"%Y-%m-%dT%H:%M:%S")
rulesProcessor(obj, current_time)
return {"success": "command applied"}
logging.debug("obj.type:" + obj.type + "command applied")
result = {"success": "command applied"}
else:
result = {"fail": "device not found"}
else:
Expand Down

0 comments on commit 52dc324

Please sign in to comment.