Class: Hue
- Inherits:
-
Object
- Object
- Hue
- Defined in:
- lib/test_driven_lighting/hue.rb
Instance Attribute Summary collapse
-
#hue_api_id ⇒ Object
Returns the value of attribute hue_api_id.
-
#hue_ip ⇒ Object
Returns the value of attribute hue_ip.
Instance Method Summary collapse
- #change!(lamp) ⇒ Object
-
#initialize(config) ⇒ Hue
constructor
A new instance of Hue.
Constructor Details
#initialize(config) ⇒ Hue
Returns a new instance of Hue.
7 8 9 10 |
# File 'lib/test_driven_lighting/hue.rb', line 7 def initialize config @hue_ip = config[:hue_ip] @hue_api_id = config[:hue_api_id] end |
Instance Attribute Details
#hue_api_id ⇒ Object
Returns the value of attribute hue_api_id.
5 6 7 |
# File 'lib/test_driven_lighting/hue.rb', line 5 def hue_api_id @hue_api_id end |
#hue_ip ⇒ Object
Returns the value of attribute hue_ip.
5 6 7 |
# File 'lib/test_driven_lighting/hue.rb', line 5 def hue_ip @hue_ip end |
Instance Method Details
#change!(lamp) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/test_driven_lighting/hue.rb', line 12 def change! lamp data = { :on => lamp.is_on, :bri => lamp.brightness, :sat => lamp.saturation, :hue => lamp.hue, :transitiontime => lamp.transition_time }.to_json connection = Faraday.new("http://#{@hue_ip}") connection.put("/api/#{@hue_api_id}/lights/#{lamp.id}/state") do |request| request.headers['Content-Type'] = 'application/json' request.headers['Accept'] = 'application/json' request.body = data end end |