Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

end wake up and add behavior_instance #979

Merged
merged 5 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion BridgeEmulator/HueObjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def __init__(self, data):
self.name = data["metadata"]["name"] if "name" in data["metadata"] else None
self.configuration = data["configuration"]
self.enabled = data["enabled"] if "enabled" in data else False
self.active = data["active"] if "active" in data else False
self.script_id = data["script_id"] if "script_id" in data else ""

streamMessage = {"creationtime": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
Expand All @@ -184,6 +185,7 @@ def getV2Api(self):
result = {"configuration": self.configuration,
"dependees": [],
"enabled": self.enabled,
"active": self.active,
"id": self.id_v2,
"last_error": "",
"metadata": {
Expand Down Expand Up @@ -227,7 +229,7 @@ def update_attr(self, newdata):
eventstream.append(streamMessage)

def save(self):
result = {"id": self.id_v2, "metadata": {"name": self.name}, "configuration": self.configuration, "enabled": self.enabled,
result = {"id": self.id_v2, "metadata": {"name": self.name}, "configuration": self.configuration, "enabled": self.enabled, "active": self.active,
"script_id": self.script_id}
if self.name != None:
result["metadata"] = {"name": self.name}
Expand Down
3 changes: 3 additions & 0 deletions BridgeEmulator/flaskUI/v2restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ def get(self):
# group
for key, group in bridgeConfig["groups"].items():
data.append(group.getV2GroupedLight())
# behavior_instance
for key, instance in bridgeConfig["behavior_instance"].items():
data.append(instance.getV2Api())
# entertainment_configuration
for key, group in bridgeConfig["groups"].items():
if group.type == "Entertainment":
Expand Down
30 changes: 21 additions & 9 deletions BridgeEmulator/functions/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,27 @@ def triggerScript(behavior_instance):

# Wake Up
if behavior_instance.script_id == "ff8957e3-2eb9-4699-a0c8-ad2cb3ede704":
logging.debug("Start Wake Up routine")
for element in behavior_instance.configuration["where"]:
if "group" in element:
group = findGroup(element["group"]["rid"])
group.setV1Action(state={"ct": 250, "bri": 1})
sleep(1)
group.setV1Action(state={"on": True})
group.setV1Action(state={"bri": 254, "transitiontime": behavior_instance.configuration["fade_in_duration"]["seconds"] * 10})
logging.debug("Finish Wake Up")
if behavior_instance.active:
logging.debug("End Wake Up routine")
for element in behavior_instance.configuration["where"]:
if "group" in element:
group = findGroup(element["group"]["rid"])
sleep(1)
group.setV1Action(state={"on": False})
behavior_instance.active = False
logging.debug("End Wake Up")

else:
logging.debug("Start Wake Up routine")
for element in behavior_instance.configuration["where"]:
if "group" in element:
group = findGroup(element["group"]["rid"])
group.setV1Action(state={"ct": 250, "bri": 1})
sleep(1)
group.setV1Action(state={"on": True})
group.setV1Action(state={"bri": 254, "transitiontime": behavior_instance.configuration["fade_in_duration"]["seconds"] * 10})
behavior_instance.active = True
logging.debug("Finish Wake Up")

# Go to sleep
elif behavior_instance.script_id == "7e571ac6-f363-42e1-809a-4cbf6523ed72":
Expand Down
6 changes: 3 additions & 3 deletions BridgeEmulator/services/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def runScheduler():
hour = triggerTime["hour"],
minute = triggerTime["minute"],
second = triggerTime["second"] if "second" in triggerTime else 0)
if "fade_in_duration" in obj.configuration:
fade_duration = obj.configuration["fade_in_duration"]
if "fade_in_duration" in obj.configuration or "turn_lights_off_after" in obj.configuration:
fade_duration = obj.configuration["turn_lights_off_after"] if obj.active else obj.configuration["fade_in_duration"]
delta = timedelta(
hours=fade_duration["hours"] if "hours" in fade_duration else 0,
minutes=fade_duration["minutes"] if "minutes" in fade_duration else 0,
seconds=fade_duration["seconds"] if "seconds" in fade_duration else 0)
time_object = time_object - delta
time_object = time_object + delta if obj.active else time_object - delta
if datetime.now().second == time_object.second and datetime.now().minute == time_object.minute and datetime.now().hour == time_object.hour:
logging.info("execute timmer: " + obj.name)
Thread(target=triggerScript, args=[obj]).start()
Expand Down