From 6f9ba9db45df736dc666041ec4d31842f58dcc57 Mon Sep 17 00:00:00 2001 From: William Le Date: Wed, 24 Aug 2022 16:32:12 +0800 Subject: [PATCH 1/4] feat(axiom/logic): add room logic --- drivers/rhb_access/axiomroomlogic.cr | 35 ++++++++++++++++++++++++++++ drivers/rhb_access/axiomxa.cr | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 drivers/rhb_access/axiomroomlogic.cr diff --git a/drivers/rhb_access/axiomroomlogic.cr b/drivers/rhb_access/axiomroomlogic.cr new file mode 100644 index 0000000000..9585dfd5e9 --- /dev/null +++ b/drivers/rhb_access/axiomroomlogic.cr @@ -0,0 +1,35 @@ +require "placeos-driver" + +class RHBAccess::AxiomRoomLogic < PlaceOS::Driver + descriptive_name "Room Access Logic for Axiom rooms" + generic_name :RoomAccess + description "Abstracts room access for Axiom" + + default_settings({ + axiom_door_ids: [] of Int32 + }) + + accessor axiom : AxiomXa + + @door_ids : Array(Int32) = [] of Int32 + + def on_load + on_update + end + + def on_update + @door_ids = setting(Array(Int32), :axiom_door_ids) + end + + def lock + @door_ids.map { |d| axiom.lock(d) } + self["locked_at"] = Time.local + self["doors_locked"] = true + end + + def unlock + @door_ids.map { |d| axiom.unlock(d) } + self["unlocked_at"] = Time.local + self["doors_locked"] = false + end +end diff --git a/drivers/rhb_access/axiomxa.cr b/drivers/rhb_access/axiomxa.cr index d392e60668..b71c613379 100644 --- a/drivers/rhb_access/axiomxa.cr +++ b/drivers/rhb_access/axiomxa.cr @@ -3,7 +3,7 @@ require "axio" class RHBAccess::Axiomxa < PlaceOS::Driver descriptive_name "RHB Access Axiomxa" - generic_name :Campus + generic_name :AxiomXa uri_base "http://127.0.0.1:60001" alias Client = Axio::Client From d55708095acb6829137adf1d6896abd7cf89949c Mon Sep 17 00:00:00 2001 From: William Le Date: Wed, 24 Aug 2022 16:44:32 +0800 Subject: [PATCH 2/4] fix(axiom/logic): ids are string not int --- drivers/rhb_access/axiomroomlogic.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rhb_access/axiomroomlogic.cr b/drivers/rhb_access/axiomroomlogic.cr index 9585dfd5e9..d86f6acdf2 100644 --- a/drivers/rhb_access/axiomroomlogic.cr +++ b/drivers/rhb_access/axiomroomlogic.cr @@ -11,14 +11,14 @@ class RHBAccess::AxiomRoomLogic < PlaceOS::Driver accessor axiom : AxiomXa - @door_ids : Array(Int32) = [] of Int32 + @door_ids = [] of String def on_load on_update end def on_update - @door_ids = setting(Array(Int32), :axiom_door_ids) + @door_ids = setting(Array(String), :axiom_door_ids) end def lock From 5d34e624ccf72c40f2af4136b9eb816006e3d382 Mon Sep 17 00:00:00 2001 From: William Le Date: Wed, 24 Aug 2022 16:53:35 +0800 Subject: [PATCH 3/4] fix(axiom/logic): ids are string not int --- drivers/rhb_access/axiomroomlogic.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/rhb_access/axiomroomlogic.cr b/drivers/rhb_access/axiomroomlogic.cr index d86f6acdf2..a3a98669e0 100644 --- a/drivers/rhb_access/axiomroomlogic.cr +++ b/drivers/rhb_access/axiomroomlogic.cr @@ -6,7 +6,7 @@ class RHBAccess::AxiomRoomLogic < PlaceOS::Driver description "Abstracts room access for Axiom" default_settings({ - axiom_door_ids: [] of Int32 + axiom_door_ids: [] of String }) accessor axiom : AxiomXa From 5e71d9ece79509d4870fd7f171144aaac3b70733 Mon Sep 17 00:00:00 2001 From: William Le Date: Wed, 24 Aug 2022 17:11:08 +0800 Subject: [PATCH 4/4] style(axiom): lint --- drivers/rhb_access/axiomroomlogic.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/rhb_access/axiomroomlogic.cr b/drivers/rhb_access/axiomroomlogic.cr index a3a98669e0..a54c61cf90 100644 --- a/drivers/rhb_access/axiomroomlogic.cr +++ b/drivers/rhb_access/axiomroomlogic.cr @@ -6,13 +6,13 @@ class RHBAccess::AxiomRoomLogic < PlaceOS::Driver description "Abstracts room access for Axiom" default_settings({ - axiom_door_ids: [] of String + axiom_door_ids: [] of String, }) accessor axiom : AxiomXa @door_ids = [] of String - + def on_load on_update end