Class: Hue::Bridge

Inherits:
Object
  • Object
show all
Defined in:
lib/hue/bridge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject (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_uriObject (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_lightsObject



21
22
23
# File 'lib/hue/bridge.rb', line 21

def add_lights
  create(uri('lights'))
end

#bulbsObject



41
42
43
# File 'lib/hue/bridge.rb', line 41

def bulbs
  @bulbs ||= lights.keys.map { |b| Bulb.new(self, b) }
end

#configObject



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_namesObject



29
30
31
# File 'lib/hue/bridge.rb', line 29

def light_names
  lights.map { |k,v| "#{k}. #{v['name']}" }.join("\n")
end

#lightsObject



25
26
27
# File 'lib/hue/bridge.rb', line 25

def lights
  index(uri('lights'))
end

#registerObject

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

#schedulesObject



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

#statusObject



17
18
19
# File 'lib/hue/bridge.rb', line 17

def status
  index(uri)
end

#unregisterObject



61
62
63
# File 'lib/hue/bridge.rb', line 61

def unregister
  delete(uri('config', 'whitelist', application_id))
end