Class: Hue::Bridge
- Inherits:
-
Object
- Object
- Hue::Bridge
- Defined in:
- lib/hue/bridge.rb
Instance Attribute Summary collapse
-
#application_id ⇒ Object
readonly
Returns the value of attribute application_id.
-
#bridge_uri ⇒ Object
readonly
Returns the value of attribute bridge_uri.
Instance Method Summary collapse
- #add_lights ⇒ Object
- #bulbs ⇒ Object
- #config ⇒ Object
- #get_light(id) ⇒ Object
-
#initialize(application_id, bridge_uri) ⇒ Bridge
constructor
A new instance of Bridge.
- #light_names ⇒ Object
- #lights ⇒ Object
-
#register ⇒ Object
def remove_all_schedules ids = schedules.keys.map(&:to_i).sort.reverse puts “Removing #idsids.size schedule#if ids.size != 1…” ids.each{|x| remove_schedule x} end.
- #schedules ⇒ Object
- #set_light(id, property) ⇒ Object
- #set_light_state(id, state) ⇒ Object
- #status ⇒ Object
- #unregister ⇒ Object
Constructor Details
#initialize(application_id, bridge_uri) ⇒ Bridge
Returns a new instance of Bridge.
12 13 14 15 |
# File 'lib/hue/bridge.rb', line 12 def initialize(application_id, bridge_uri) @application_id = application_id @bridge_uri = bridge_uri end |
Instance Attribute Details
#application_id ⇒ Object (readonly)
Returns the value of attribute application_id.
10 11 12 |
# File 'lib/hue/bridge.rb', line 10 def application_id @application_id end |
#bridge_uri ⇒ Object (readonly)
Returns the value of attribute bridge_uri.
10 11 12 |
# File 'lib/hue/bridge.rb', line 10 def bridge_uri @bridge_uri end |
Instance Method Details
#add_lights ⇒ Object
21 22 23 |
# File 'lib/hue/bridge.rb', line 21 def add_lights create(uri('lights')) end |
#bulbs ⇒ Object
41 42 43 |
# File 'lib/hue/bridge.rb', line 41 def bulbs @bulbs ||= lights.keys.map { |b| Bulb.new(self, b) } end |
#config ⇒ Object
33 34 35 |
# File 'lib/hue/bridge.rb', line 33 def config index(uri('config')) end |
#get_light(id) ⇒ Object
65 66 67 |
# File 'lib/hue/bridge.rb', line 65 def get_light(id) index(uri('lights', id)) end |
#light_names ⇒ Object
29 30 31 |
# File 'lib/hue/bridge.rb', line 29 def light_names lights.map { |k,v| "#{k}. #{v['name']}" }.join("\n") end |
#lights ⇒ Object
25 26 27 |
# File 'lib/hue/bridge.rb', line 25 def lights index(uri('lights')) end |
#register ⇒ Object
def remove_all_schedules
ids = schedules.keys.map(&:to_i).sort.reverse
puts "Removing #{ids.size} schedule#{'s' if ids.size != 1}..."
ids.each{|x| remove_schedule x}
end
56 57 58 59 |
# File 'lib/hue/bridge.rb', line 56 def register create(URI.parse(bridge_uri), {"username" => application_id, "devicetype" => Hue.device_type}) end |
#schedules ⇒ Object
37 38 39 |
# File 'lib/hue/bridge.rb', line 37 def schedules index(uri('schedules')) end |
#set_light(id, property) ⇒ Object
69 70 71 |
# File 'lib/hue/bridge.rb', line 69 def set_light(id, property) update(uri('lights', id), property) end |
#set_light_state(id, state) ⇒ Object
73 74 75 |
# File 'lib/hue/bridge.rb', line 73 def set_light_state(id, state) update(uri('lights', id, 'state'), state) end |
#status ⇒ Object
17 18 19 |
# File 'lib/hue/bridge.rb', line 17 def status index(uri) end |
#unregister ⇒ Object
61 62 63 |
# File 'lib/hue/bridge.rb', line 61 def unregister delete(uri('config', 'whitelist', application_id)) end |