Sha256: fbf7893ab3b42d0e79ce566952cebb8f52a0024eb28cf9823f5fcabf1c3214b5

Contents?: true

Size: 730 Bytes

Versions: 2

Compression:

Stored size: 730 Bytes

Contents

require 'json'
require 'faraday'

class Hue
  attr_accessor :hue_ip, :hue_api_id

  def initialize config
    @hue_ip     = config[:hue_ip]
    @hue_api_id = config[:hue_api_id]
  end

  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
test_driven_lighting-1.2.0 lib/test_driven_lighting/hue.rb
test_driven_lighting-1.1.0 lib/test_driven_lighting/hue.rb