From ac72ba1f12ee2bc65fcc807233a2fb33b205481e Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Mon, 22 Dec 2014 20:44:43 -0800 Subject: [PATCH] specify brightness and temp for named settings --- lights | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/lights b/lights index d67dda3..65b769b 100755 --- a/lights +++ b/lights @@ -4,13 +4,34 @@ require 'huemote' LIGHT_NAMES = ['Office 1', 'Office 2'] TEMPS = { - 'bright' => 4200, - 'cloudy' => 3500, - 'sunrise' => 2200, - 'morning' => 2600, - 'noon' => 4200, - 'sunset' => 2600, - 'night' => 2200, + 'bright' => { + brightness: 100, + temp: 4200, + }, + 'cloudy' => { + brightness: 90, + 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['overcast'] = TEMPS['cloudy'] @@ -26,9 +47,19 @@ when 'on' lights.each(&:on!) else lights.each(&:on!) - temp = TEMPS[setting] || setting.to_i - if temp > 0 - lights.each { |l| l.kelvin(temp) } + attrs = TEMPS[setting] || { + brightness: (ARGV[1] || 80).to_i, + 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 puts "Unknown setting: #{setting}" end