Created
December 14, 2014 19:47
-
-
Save nuc/775c5f3c6d0e0775b578 to your computer and use it in GitHub Desktop.
LIFX gem wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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