From 5b380b50194d39fcfdd4436a16eb554c9357d15f Mon Sep 17 00:00:00 2001 From: Giorgi Kavrelishvili Date: Mon, 27 Jun 2022 11:39:20 +0400 Subject: [PATCH 1/8] Add Quantum driver --- drivers/lutron/quantum.cr | 54 +++++++++++++++++++++++++++++++++++++++ shard.lock | 32 ++++++++++++++--------- shard.yml | 4 +++ 3 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 drivers/lutron/quantum.cr diff --git a/drivers/lutron/quantum.cr b/drivers/lutron/quantum.cr new file mode 100644 index 00000000000..c89402bc575 --- /dev/null +++ b/drivers/lutron/quantum.cr @@ -0,0 +1,54 @@ +require "placeos-driver" +require "quantum" + +class Lutron::Quantum < PlaceOS::Driver + descriptive_name "Lutron Quantum Gateway" + generic_name :Lighting + uri_base "https://engineeringwebdemo01.lutron.com/" + + alias Client = ::Quantum::Client + + default_settings({ + api_key: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + device_key: "ab22c585-14e6-4c6b-b418-166728bcc608", + }) + + @client : Client = Client.new(host_name: "", api_key: "", device_key: "") + + def on_load + on_update + end + + def on_update + host_name = URI.parse(config.uri.not_nil!).host + api_key = setting(String, :api_key) + device_key = setting(String, :device_key) + + @client = Client.new(host_name: host_name.not_nil!, api_key: api_key, device_key: device_key) + end + + def level?(id : Int32) + status = @client.zone.get_status(id) + self["area#{id}_level"] = status["Level"] + end + + def level(id : Int32, level : String) + @client.zone.set_status_level(id: id, level: level) + self["area#{id}_level"] = level + end + + def scene(id : Int32, scene : Int32) + @client.area.set_scene(id: id, scene: scene) + self["area#{id}"] = scene + end + + def scene?(id : Int32) + status = @client.area.get_status(id: id) + self["area#{id}"] = status["CurrentScene"] + end + + @[PlaceOS::Driver::Security(Level::Support)] + def scenes(id : Int32) + @client.area.get_scenes(id: id) + end +end diff --git a/shard.lock b/shard.lock index 2b14552a9d0..05ff36eaf27 100644 --- a/shard.lock +++ b/shard.lock @@ -55,11 +55,11 @@ shards: debug: git: https://github.com/sija/debug.cr.git - version: 2.0.1 + version: 2.0.2 defined: git: https://github.com/wyhaines/defined.cr.git - version: 0.3.4 + version: 0.3.6 dtls: git: https://github.com/spider-gazelle/crystal-dtls.git @@ -91,7 +91,7 @@ shards: google: git: https://github.com/placeos/google.git - version: 3.3.1 + version: 3.4.0 habitat: git: https://github.com/luckyframework/habitat.git @@ -117,6 +117,10 @@ shards: git: https://github.com/sija/ipaddress.cr.git version: 0.2.1 + json-merge-patch: + git: https://github.com/caspiano/json-merge-patch.git + version: 0.1.1 + jwt: git: https://github.com/crystal-community/jwt.git version: 1.6.0 @@ -147,7 +151,7 @@ shards: neuroplastic: git: https://github.com/spider-gazelle/neuroplastic.git - version: 1.11.0 + version: 1.12.0 ntlm: git: https://github.com/spider-gazelle/ntlm.git @@ -155,7 +159,7 @@ shards: office365: git: https://github.com/placeos/office365.git - version: 1.17.2 + version: 1.18.0 open_api: git: https://github.com/elbywan/open_api.cr.git @@ -171,11 +175,11 @@ shards: opentelemetry-api: git: https://github.com/wyhaines/opentelemetry-api.cr.git - version: 0.3.0 + version: 0.3.4 opentelemetry-instrumentation: git: https://github.com/wyhaines/opentelemetry-instrumentation.cr.git - version: 0.3.2+git.commit.47a7b5c243edf08dd9f7a4e2270a7698489dcb1b + version: 0.3.5 oq: git: https://github.com/blacksmoke16/oq.git @@ -195,11 +199,11 @@ shards: place_calendar: git: https://github.com/placeos/calendar.git - version: 4.14.0 + version: 4.15.4 placeos: git: https://github.com/placeos/crystal-client.git - version: 2.7.0 + version: 2.7.2 placeos-compiler: git: https://github.com/placeos/compiler.git @@ -211,15 +215,15 @@ shards: placeos-driver: git: https://github.com/placeos/driver.git - version: 6.3.7 + version: 6.3.8 placeos-log-backend: git: https://github.com/place-labs/log-backend.git - version: 0.10.2 + version: 0.10.5 placeos-models: git: https://github.com/placeos/models.git - version: 8.9.1 + version: 8.11.0 pool: git: https://github.com/ysbaddaden/pool.git @@ -237,6 +241,10 @@ shards: git: https://github.com/spider-gazelle/qr-code.git version: 1.0.2 + quantum: + git: https://github.com/place-technology/quantum.git + version: 0.1.1 + rate_limiter: git: https://github.com/lbarasti/rate_limiter.git version: 1.0.1 diff --git a/shard.yml b/shard.yml index 95d8f7b9a73..bcf6ccae53f 100644 --- a/shard.yml +++ b/shard.yml @@ -100,3 +100,7 @@ dependencies: # fake data for mocks faker: github: askn/faker + + # Lutron Quantum protocol + quantum: + github: place-technology/quantum From 9a77276975d0dfb22130bf063186c3d1b0c1c14d Mon Sep 17 00:00:00 2001 From: Giorgi Kavrelishvili Date: Mon, 27 Jun 2022 13:53:06 +0400 Subject: [PATCH 2/8] Update the initialization with a getter --- drivers/lutron/quantum.cr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/lutron/quantum.cr b/drivers/lutron/quantum.cr index c89402bc575..c82ed336da6 100644 --- a/drivers/lutron/quantum.cr +++ b/drivers/lutron/quantum.cr @@ -13,7 +13,7 @@ class Lutron::Quantum < PlaceOS::Driver device_key: "ab22c585-14e6-4c6b-b418-166728bcc608", }) - @client : Client = Client.new(host_name: "", api_key: "", device_key: "") + protected getter! client : Client def on_load on_update @@ -28,27 +28,27 @@ class Lutron::Quantum < PlaceOS::Driver end def level?(id : Int32) - status = @client.zone.get_status(id) - self["area#{id}_level"] = status["Level"] + status = @client.try(&.zone.get_status(id)) + self["area#{id}_level"] = status.try(&.["Level"]) end def level(id : Int32, level : String) - @client.zone.set_status_level(id: id, level: level) + @client.try(&.zone.set_status_level(id: id, level: level)) self["area#{id}_level"] = level end def scene(id : Int32, scene : Int32) - @client.area.set_scene(id: id, scene: scene) + @client.try(&.area.set_scene(id: id, scene: scene)) self["area#{id}"] = scene end def scene?(id : Int32) - status = @client.area.get_status(id: id) - self["area#{id}"] = status["CurrentScene"] + status = @client.try(&.area.get_status(id: id)) + self["area#{id}"] = status.try(&.["CurrentScene"]) end @[PlaceOS::Driver::Security(Level::Support)] def scenes(id : Int32) - @client.area.get_scenes(id: id) + @client.try(&.area.get_scenes(id: id)) end end From fa2af958e66ece098bfd8a1dd4ffae7f4021cf2a Mon Sep 17 00:00:00 2001 From: Giorgi Kavrelishvili Date: Thu, 21 Jul 2022 08:54:44 +0400 Subject: [PATCH 3/8] Error on client being null --- drivers/lutron/quantum.cr | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/lutron/quantum.cr b/drivers/lutron/quantum.cr index c82ed336da6..6eb171b1952 100644 --- a/drivers/lutron/quantum.cr +++ b/drivers/lutron/quantum.cr @@ -28,27 +28,32 @@ class Lutron::Quantum < PlaceOS::Driver end def level?(id : Int32) - status = @client.try(&.zone.get_status(id)) - self["area#{id}_level"] = status.try(&.["Level"]) + status = client.zone.get_status(id) + self["area#{id}_level"] = status["Level"] end def level(id : Int32, level : String) - @client.try(&.zone.set_status_level(id: id, level: level)) + client.zone.set_status_level(id: id, level: level) self["area#{id}_level"] = level end def scene(id : Int32, scene : Int32) - @client.try(&.area.set_scene(id: id, scene: scene)) + client.area.set_scene(id: id, scene: scene) self["area#{id}"] = scene end def scene?(id : Int32) - status = @client.try(&.area.get_status(id: id)) - self["area#{id}"] = status.try(&.["CurrentScene"]) + status = client.area.get_status(id: id) + self["area#{id}"] = status["CurrentScene"] end @[PlaceOS::Driver::Security(Level::Support)] def scenes(id : Int32) - @client.try(&.area.get_scenes(id: id)) + client.area.get_scenes(id: id) + end + + @[PlaceOS::Driver::Security(Level::Support)] + def root + client.area.root end end From 5c25aed6421e59e0467664f27ebdb5999002dce6 Mon Sep 17 00:00:00 2001 From: William Le Date: Wed, 24 Aug 2022 21:11:48 +0800 Subject: [PATCH 4/8] feat(lutron/quantum): add area query --- drivers/lutron/quantum.cr | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/lutron/quantum.cr b/drivers/lutron/quantum.cr index 6eb171b1952..e98c6ded531 100644 --- a/drivers/lutron/quantum.cr +++ b/drivers/lutron/quantum.cr @@ -32,11 +32,13 @@ class Lutron::Quantum < PlaceOS::Driver self["area#{id}_level"] = status["Level"] end + @[PlaceOS::Driver::Security(Level::Support)] def level(id : Int32, level : String) client.zone.set_status_level(id: id, level: level) self["area#{id}_level"] = level end + @[PlaceOS::Driver::Security(Level::Support)] def scene(id : Int32, scene : Int32) client.area.set_scene(id: id, scene: scene) self["area#{id}"] = scene @@ -47,11 +49,14 @@ class Lutron::Quantum < PlaceOS::Driver self["area#{id}"] = status["CurrentScene"] end - @[PlaceOS::Driver::Security(Level::Support)] - def scenes(id : Int32) + def scenes?(id : Int32) client.area.get_scenes(id: id) end + def area?(id : Int32) + client.area.get_by_id(id: id) + end + @[PlaceOS::Driver::Security(Level::Support)] def root client.area.root From 325794d27b67c7722b3dd6060cb91b1f6cb90c96 Mon Sep 17 00:00:00 2001 From: William Le Date: Wed, 24 Aug 2022 21:22:15 +0800 Subject: [PATCH 5/8] feat(lutron/quantum): add zones query --- drivers/lutron/quantum.cr | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/lutron/quantum.cr b/drivers/lutron/quantum.cr index e98c6ded531..b49dd1530c9 100644 --- a/drivers/lutron/quantum.cr +++ b/drivers/lutron/quantum.cr @@ -27,34 +27,38 @@ class Lutron::Quantum < PlaceOS::Driver @client = Client.new(host_name: host_name.not_nil!, api_key: api_key, device_key: device_key) end - def level?(id : Int32) - status = client.zone.get_status(id) - self["area#{id}_level"] = status["Level"] + def level?(zone_id : Int32) + status = client.zone.get_status(zone_id) + self["area#{zone_id}_level"] = status["Level"] end @[PlaceOS::Driver::Security(Level::Support)] - def level(id : Int32, level : String) - client.zone.set_status_level(id: id, level: level) - self["area#{id}_level"] = level + def level(zone_id : Int32, level : String) + client.zone.set_status_level(id: zone_id, level: level) + self["zone#{zone_id}_level"] = level end @[PlaceOS::Driver::Security(Level::Support)] - def scene(id : Int32, scene : Int32) - client.area.set_scene(id: id, scene: scene) - self["area#{id}"] = scene + def scene(area_id : Int32, scene : Int32) + client.area.set_scene(id: area_id, scene: scene) + self["area#{area_id}"] = scene end - def scene?(id : Int32) - status = client.area.get_status(id: id) - self["area#{id}"] = status["CurrentScene"] + def scene?(area_id : Int32) + status = client.area.get_status(area_id: area_id) + self["area#{area_id}"] = status["CurrentScene"] end - def scenes?(id : Int32) - client.area.get_scenes(id: id) + def scenes?(area_id : Int32) + client.area.get_scenes(id: area_id) end - def area?(id : Int32) - client.area.get_by_id(id: id) + def area?(area_id : Int32) + client.area.get_by_id(id: area_id) + end + + def zones?(area_id : Int32) + client.area.get_zones(id: area_id) end @[PlaceOS::Driver::Security(Level::Support)] From cdf755274e74821b601fdd290daa98fed48c9018 Mon Sep 17 00:00:00 2001 From: William Le Date: Wed, 24 Aug 2022 21:26:06 +0800 Subject: [PATCH 6/8] fix(lutron/quantum): scenes? --- drivers/lutron/quantum.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/lutron/quantum.cr b/drivers/lutron/quantum.cr index b49dd1530c9..95f6cf6ea63 100644 --- a/drivers/lutron/quantum.cr +++ b/drivers/lutron/quantum.cr @@ -45,7 +45,7 @@ class Lutron::Quantum < PlaceOS::Driver end def scene?(area_id : Int32) - status = client.area.get_status(area_id: area_id) + status = client.area.get_status(id: area_id) self["area#{area_id}"] = status["CurrentScene"] end From 6a704dfcb74e845086cbf7b894be1c2d0de2f963 Mon Sep 17 00:00:00 2001 From: William Le Date: Wed, 24 Aug 2022 23:48:13 +1000 Subject: [PATCH 7/8] chore(shard.lock): patch quantum --- shard.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shard.lock b/shard.lock index aaef6cb75cf..0574f249c2a 100644 --- a/shard.lock +++ b/shard.lock @@ -243,7 +243,7 @@ shards: quantum: git: https://github.com/place-technology/quantum.git - version: 0.1.1 + version: 0.1.2 rate_limiter: git: https://github.com/lbarasti/rate_limiter.git From 0870962034fae63d6d740ecb8cb5517b140f6d41 Mon Sep 17 00:00:00 2001 From: William Le Date: Fri, 26 Aug 2022 09:31:57 +0800 Subject: [PATCH 8/8] feat(lutron/quantum): get area,zones. fix get scenes