Skip to content

Instantly share code, notes, and snippets.

@nuc
Created December 14, 2014 19:47
Show Gist options
  • Save nuc/775c5f3c6d0e0775b578 to your computer and use it in GitHub Desktop.
Save nuc/775c5f3c6d0e0775b578 to your computer and use it in GitHub Desktop.
LIFX gem wrapper
require 'rubygems'
require 'lifx'
class Lifx
attr_reader :client, :light
def initialize
@client = LIFX::Client.lan
@client.discover! do |c|
c.lights.with_label('')
end
@light = @client.lights.first
end
def default
light.set_color(LIFX::Color.new(0,0,1,3500), duration: 0)
end
def green
set color: LIFX::Colors.green
end
def red
set color: LIFX::Colors.red
end
def pinkish
set hue: 0, saturation: 0.3
end
def another
set hue: 0, saturation: 0.3, brightness: 1, temperature: 4500
end
def set(options)
if options[:color]
color = options[:color]
else
hue = options[:hue]
saturation = options[:saturation]
brightness = options[:brightness] || 1
temperature = options[:temperature] || 3500
color = LIFX::Color.new(hue, saturation, brightness, temperature)
end
duration = options[:duration] || 0
light.set_color(color, duration: duration)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment