Skip to content
Merged
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
34 changes: 34 additions & 0 deletions drivers/lutron/room_logic.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 :RoomLighting
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.clear
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