Class: Hue

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject

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_ipObject

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