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

Feature/quantum #502

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
68 changes: 68 additions & 0 deletions drivers/lutron/quantum.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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",
})

protected getter! client : Client

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?(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(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(area_id : Int32, scene : Int32)
client.area.set_scene(id: area_id, scene: scene)
self["area#{area_id}"] = scene
end

def scene?(area_id : Int32)
status = client.area.get_status(id: area_id)
self["area#{area_id}"] = status["CurrentScene"]
end

def scenes?(area_id : Int32)
client.area.get_scenes(id: area_id)
end

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)]
def root
client.area.root
end
end
4 changes: 4 additions & 0 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -241,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.2

rate_limiter:
git: https://github.com/lbarasti/rate_limiter.git
version: 1.0.1
Expand Down
4 changes: 4 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ dependencies:
# fake data for mocks
faker:
github: askn/faker

# Lutron Quantum protocol
quantum:
github: place-technology/quantum