Created
May 20, 2015 21:27
-
-
Save NateBarnes/0e4f54f087653ec338a8 to your computer and use it in GitHub Desktop.
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 'bundler' | |
Bundler.require | |
require 'socket' | |
require 'redis' | |
a = TCPServer.new('', MY_SECRET_PORT_NUMBER) # '' means to bind to "all interfaces", same as nil or '0.0.0.0' | |
c = LIFX::Client.lan | |
c.discover | |
5.times do | |
c.lights.refresh | |
c.flush | |
sleep 1 | |
end | |
lightarray = [] | |
c.lights.each do |bulb| | |
lightarray << "label=" + bulb.label.to_s + ", power=" + bulb.power.to_s + ", " + bulb.color.to_s | |
end | |
#redis.set "light_list", lightarray | |
def change_light_state_by_label label, state | |
loop do | |
c.lights.with_label(label).send "turn_#{state}" | |
c.flush | |
sleep 2 | |
break if c.lights.with_label(label).power.to_s == state | |
end | |
rescue | |
puts 'tripod2 on failed' | |
end | |
loop do | |
connection = a.accept | |
data = connection.recv(1024) | |
change_light_state_by_label(*data.split("_")) | |
#MANY MANY MORE CASE STATEMENTS HERE | |
sleep 1 | |
connection.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment