Class: Lono::Device
- Inherits:
-
Object
- Object
- Lono::Device
- Defined in:
- lib/lono-api/device.rb
Constant Summary collapse
- VALID_DEVICE_REGEX =
/[a-f0-9]{24}/
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#session_token ⇒ Object
readonly
Returns the value of attribute session_token.
Instance Method Summary collapse
-
#detect_zones ⇒ Object
detect_zones().
-
#get_lono_info ⇒ Object
get_lono_info().
-
#get_zone ⇒ Object
get_zone(cb).
-
#get_zones_info ⇒ Object
get_zones_info().
-
#initialize(device_id, session_token) ⇒ Device
constructor
A new instance of Device.
-
#put_zones(zones) ⇒ Object
put_zones(zones).
- #set_led(color, brightness) ⇒ Object
- #set_led_options(options) ⇒ Object
- #set_zone(zone_id, action) ⇒ Object
Constructor Details
#initialize(device_id, session_token) ⇒ Device
Returns a new instance of Device.
7 8 9 10 11 |
# File 'lib/lono-api/device.rb', line 7 def initialize(device_id, session_token) @id = device_id @session_token = session_token validate! end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/lono-api/device.rb', line 5 def id @id end |
#session_token ⇒ Object (readonly)
Returns the value of attribute session_token.
5 6 7 |
# File 'lib/lono-api/device.rb', line 5 def session_token @session_token end |
Instance Method Details
#detect_zones ⇒ Object
detect_zones()
Run a zone detect sequence to discover which zones have been attached to Lono.
87 88 89 90 91 92 |
# File 'lib/lono-api/device.rb', line 87 def detect_zones query_device @id, { :url => "zones/detect", :method => "post" } end |
#get_lono_info ⇒ Object
get_lono_info()
Get a bunch of metadata that is stored internally with Lono, like hardware revision information and basic sceduling options.
61 62 63 64 65 66 |
# File 'lib/lono-api/device.rb', line 61 def get_lono_info query_device @id, { :url => "", :method => "get" } end |
#get_zone ⇒ Object
get_zone(cb)
Get the current zone that is enabled on Lono (No zone on will be None).
> lc = LonoClient(client_id=“…”, …) # etc… ** connect to lono cloud ** > lc.get_device(“device id”).get_zone(function() {})
27 28 29 30 31 32 |
# File 'lib/lono-api/device.rb', line 27 def get_zone query_device @id, { :url => "zones/state", :method => "get" } end |
#get_zones_info ⇒ Object
get_zones_info()
Get a bunch of metadata that is stored internally with each Zone, like cycle time and soil type.
74 75 76 77 78 79 |
# File 'lib/lono-api/device.rb', line 74 def get_zones_info query_device @id, { :url => "zones", :method => "get" } end |
#put_zones(zones) ⇒ Object
put_zones(zones)
Update the zones zonnected to a Lono with the zones specified. zones is an array of zone objects (like what you’d receive from get_zones_info).
100 101 102 103 104 105 106 107 108 |
# File 'lib/lono-api/device.rb', line 100 def put_zones(zones) query_device @id, { :url => "zones", :method => "put", :body => { :zones => zones } } end |
#set_led(color, brightness) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lono-api/device.rb', line 35 def set_led(color, brightness) query_device @id, { :url => "state", :method => "post", :body => { :color => color, :brightness => brightness } } end |
#set_led_options(options) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/lono-api/device.rb', line 46 def () query_device @id, { :url => "state", :method => "post", :body => } end |
#set_zone(zone_id, action) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/lono-api/device.rb', line 13 def set_zone(zone_id, action) query_device @id, { :url => "zones/#{zone_id}/#{action and "on" or "off"}", :method => "post" } end |