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.
Class Method Summary collapse
-
.register(bridge_uri) ⇒ 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.
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
- #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 |
Class Method Details
.register(bridge_uri) ⇒ 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 60 |
# File 'lib/hue/bridge.rb', line 56 def self.register(bridge_uri) instance = self.new("", bridge_uri) instance.register instance 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
73 74 75 |
# File 'lib/hue/bridge.rb', line 73 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
62 63 64 65 66 67 |
# File 'lib/hue/bridge.rb', line 62 def register response = create(URI.parse(bridge_uri), {"devicetype" => "#{Hue.device_type}@#{Socket.gethostname}"}) if response.first.has_key?('success') @application_id = response.first['success']['username'] end end |
#schedules ⇒ Object
37 38 39 |
# File 'lib/hue/bridge.rb', line 37 def schedules index(uri('schedules')) end |
#set_light(id, property) ⇒ Object
77 78 79 |
# File 'lib/hue/bridge.rb', line 77 def set_light(id, property) update(uri('lights', id), property) end |
#set_light_state(id, state) ⇒ Object
81 82 83 |
# File 'lib/hue/bridge.rb', line 81 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
69 70 71 |
# File 'lib/hue/bridge.rb', line 69 def unregister delete(uri('config', 'whitelist', application_id)) end |