specify brightness and temp for named settings

This commit is contained in:
Sami Samhuri 2014-12-22 20:44:43 -08:00
parent 845d706b21
commit ac72ba1f12

51
lights
View file

@ -4,13 +4,34 @@ require 'huemote'
LIGHT_NAMES = ['Office 1', 'Office 2'] LIGHT_NAMES = ['Office 1', 'Office 2']
TEMPS = { TEMPS = {
'bright' => 4200, 'bright' => {
'cloudy' => 3500, brightness: 100,
'sunrise' => 2200, temp: 4200,
'morning' => 2600, },
'noon' => 4200, 'cloudy' => {
'sunset' => 2600, brightness: 90,
'night' => 2200, temp: 3500,
},
'sunrise' => {
brightness: 70,
temp: 2600,
},
'morning' => {
brightness: 90,
temp: 2200,
},
'noon' => {
brightness: 100,
temp: 4200,
},
'sunset' => {
brightness: 90,
temp: 2600,
},
'night' => {
brightness: 70,
temp: 2200,
},
} }
TEMPS['sunny'] = TEMPS['bright'] TEMPS['sunny'] = TEMPS['bright']
TEMPS['overcast'] = TEMPS['cloudy'] TEMPS['overcast'] = TEMPS['cloudy']
@ -26,9 +47,19 @@ when 'on'
lights.each(&:on!) lights.each(&:on!)
else else
lights.each(&:on!) lights.each(&:on!)
temp = TEMPS[setting] || setting.to_i attrs = TEMPS[setting] || {
if temp > 0 brightness: (ARGV[1] || 80).to_i,
lights.each { |l| l.kelvin(temp) } temp: setting.to_i,
}
if attrs
lights.each do |l|
if attrs[:brightness]
l.brightness(attrs[:brightness])
end
if attrs[:temp]
l.kelvin(attrs[:temp])
end
end
else else
puts "Unknown setting: #{setting}" puts "Unknown setting: #{setting}"
end end