From 6d76169023622ba9a1cb707b6d038886261c0e89 Mon Sep 17 00:00:00 2001 From: William Le Date: Thu, 15 Sep 2022 00:01:38 +0800 Subject: [PATCH 1/3] feat(lutron): add room logic --- drivers/lutron/room_logic.cr | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 drivers/lutron/room_logic.cr diff --git a/drivers/lutron/room_logic.cr b/drivers/lutron/room_logic.cr new file mode 100644 index 00000000000..e9f98439e0c --- /dev/null +++ b/drivers/lutron/room_logic.cr @@ -0,0 +1,33 @@ +require "placeos-driver" + +# Currently this logic driver is designed for Quantum only but ideally there should be just one Lutron room logic that handles all Lutron APIs +class Lutron::RoomLogic < PlaceOS::Driver + descriptive_name "Lutron Room level status " + generic_name :RoomEnvironment + description "Exposes the room's lighting state" + + default_settings({ + lutron_area_id: 0, + lutron_status_poll_cron: "*/5 * * * *", + }) + + accessor lutron : Lutron + + @area_id : Int32 = 0 + @cron_string : String = "*/5 * * * *" + + def on_load + on_update + end + + def on_update + @area_id = setting(Int32, :lutron_area_id) + @cron_string = setting(String, :lutron_status_poll_cron) + schedule.cron(@cron_string) { get_state } + end + + def get_state + self["lighting_scene"] = lutron.scene?(@area_id).get + self["occupancy"] = lutron.occupancy_status?(@area_id).get + end +end From f82aee6d2730f246ae681cfef397722eb0de2fad Mon Sep 17 00:00:00 2001 From: William Le Date: Thu, 15 Sep 2022 00:05:59 +0800 Subject: [PATCH 2/3] fix(lutron): generic_name --- drivers/lutron/room_logic.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/lutron/room_logic.cr b/drivers/lutron/room_logic.cr index e9f98439e0c..c8f47de98fb 100644 --- a/drivers/lutron/room_logic.cr +++ b/drivers/lutron/room_logic.cr @@ -3,7 +3,7 @@ require "placeos-driver" # Currently this logic driver is designed for Quantum only but ideally there should be just one Lutron room logic that handles all Lutron APIs class Lutron::RoomLogic < PlaceOS::Driver descriptive_name "Lutron Room level status " - generic_name :RoomEnvironment + generic_name :RoomLighting description "Exposes the room's lighting state" default_settings({ From 256e7449f95913f1ce9697b1842d498a67aac55c Mon Sep 17 00:00:00 2001 From: William Le Date: Thu, 15 Sep 2022 00:11:29 +0800 Subject: [PATCH 3/3] fix(lutron/logic): schedule.clear on update --- drivers/lutron/room_logic.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/lutron/room_logic.cr b/drivers/lutron/room_logic.cr index c8f47de98fb..b156781931e 100644 --- a/drivers/lutron/room_logic.cr +++ b/drivers/lutron/room_logic.cr @@ -23,6 +23,7 @@ class Lutron::RoomLogic < PlaceOS::Driver def on_update @area_id = setting(Int32, :lutron_area_id) @cron_string = setting(String, :lutron_status_poll_cron) + schedule.clear schedule.cron(@cron_string) { get_state } end