From ab6f9c8a0e158023d58cbf512b0402087a22c7d2 Mon Sep 17 00:00:00 2001 From: sarkonovich Date: Mon, 6 Apr 2015 14:23:52 -0700 Subject: [PATCH 1/5] Add mired colors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Minor change to: - Add mired colors (Hue’s “working,” “reading,” etc. - Expand standard colors (violet, orange, etc) - Removed dependency on color.rb — which wasn’t used much (I think). Moved relevant method to hue/module.rb --- server/modules/hue/module.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/modules/hue/module.rb b/server/modules/hue/module.rb index 2e78586..6303fa1 100644 --- a/server/modules/hue/module.rb +++ b/server/modules/hue/module.rb @@ -1,5 +1,5 @@ require 'hue' -require 'color.rb' + class AlexaHue @@ -13,6 +13,16 @@ def wake_words ["light", "lights"] end + def string_to_hue(string) + mired_colors = {sleeping: 500, candle: 445, relaxing: 387, neutral: 327, reading: 286, working: 227, flourescent: 180} + basic_color_hues = {red: 65280, pink: 56100, purple: 52180, violet: 47188, blue: 46920, turquoise: 31146, green: 25500, yellow: 12750, orange: 8618} + if basic_color_hues.keys.include?(string.to_sym) + directive = {hue: basic_color_hues[string.to_sym], saturation: 255} + elsif mired_colors.keys.include?(string.to_sym) + directive = {ct: mired_colors[string.to_sym]} + end + end + def process_command(command) lights_to_act_on = [] From d95c74c90a80a2ebf3d29b01aa47619203224e50 Mon Sep 17 00:00:00 2001 From: sarkonovich Date: Mon, 6 Apr 2015 15:59:13 -0700 Subject: [PATCH 2/5] Fix TypeError fix error or Google Calendar module --- server/modules/google_calendar/module.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/server/modules/google_calendar/module.rb b/server/modules/google_calendar/module.rb index af0dbdf..0783a1f 100644 --- a/server/modules/google_calendar/module.rb +++ b/server/modules/google_calendar/module.rb @@ -99,6 +99,7 @@ def parse_time(command) modifier = 'p.m.' elsif command.downcase.scan(/morning/).length > 0 modifier = 'a.m.' + else modifier = '' end complexity = time.compact.length From c68ef9b5a21a912ba47ff61b5e93a1bca9f7d357 Mon Sep 17 00:00:00 2001 From: sarkonovich Date: Mon, 6 Apr 2015 23:45:44 -0700 Subject: [PATCH 3/5] Act on groups of lights Improve the light module to automatically detect light groups instead of having to hardcode them into the module. --- server/modules/hue/module.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/modules/hue/module.rb b/server/modules/hue/module.rb index 2e78586..fdda03d 100644 --- a/server/modules/hue/module.rb +++ b/server/modules/hue/module.rb @@ -5,10 +5,12 @@ class AlexaHue HUE_CLIENT = Hue::Client.new - ZACH_ROOM_LIGHTS = ["bedside", "overhead"] - SATURATION_MODIFIERS = {lighter: 200, light: 200, darker: 255, dark: 255, darkest: 200} + GROUPS = {} + + HUE_CLIENT.groups.each do |g| GROUPS[g.name] = g.id end + def wake_words ["light", "lights"] end @@ -19,8 +21,12 @@ def process_command(command) # Select lights if command.scan(/all/).length > 0 lights_to_act_on = HUE_CLIENT.lights - elsif command.scan(/room/).length > 0 - lights_to_act_on = HUE_CLIENT.lights.select{|light| ZACH_ROOM_LIGHTS.include?(light.name.downcase)} + elsif GROUPS.keys.any? { |g| command.include?(g.downcase) } + GROUPS.keys.each do |k| + if command.include?(k.downcase) + lights_to_act_on = HUE_CLIENT.group(GROUPS[k]) + end + end else lights_to_act_on = HUE_CLIENT.lights.select{|light| command.split(" ").include?(light.name.downcase)} end From 5165f403fa552104808bdecbd3e98b102e4d2864 Mon Sep 17 00:00:00 2001 From: sarkonovich Date: Tue, 7 Apr 2015 09:41:14 -0700 Subject: [PATCH 4/5] Update module.rb Performance improvement. Commands are sent directly to groups, so all lights in group respond in unison. --- server/modules/hue/module.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server/modules/hue/module.rb b/server/modules/hue/module.rb index fdda03d..be49637 100644 --- a/server/modules/hue/module.rb +++ b/server/modules/hue/module.rb @@ -90,13 +90,17 @@ def process_command(command) def light_command(lights, options = {}) p options - lights.each do |light| - light.on = options[:on] if !options[:on].nil? - light.set_state(options[:color]) if !options[:color].nil? + if lights.class = Hue::Group + lights.on = options[:on] if !options[:on].nil? + lights.set_state(options[:color]) if !options[:color].nil? + sleep(0.5) + else lights.each do |light| + light.on = options[:on] if !options[:on].nil? + light.set_state(options[:color]) if !options[:color].nil? sleep(0.5) + end end end - end -MODULE_INSTANCES.push(AlexaHue.new) \ No newline at end of file +MODULE_INSTANCES.push(AlexaHue.new) From 9880f3e4955f1df47ab892a1459df6b70642d49b Mon Sep 17 00:00:00 2001 From: sarkonovich Date: Tue, 7 Apr 2015 09:45:08 -0700 Subject: [PATCH 5/5] Update module.rb --- server/modules/hue/module.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/modules/hue/module.rb b/server/modules/hue/module.rb index be49637..e5c5377 100644 --- a/server/modules/hue/module.rb +++ b/server/modules/hue/module.rb @@ -90,14 +90,14 @@ def process_command(command) def light_command(lights, options = {}) p options - if lights.class = Hue::Group + if lights.class == Hue::Group lights.on = options[:on] if !options[:on].nil? lights.set_state(options[:color]) if !options[:color].nil? sleep(0.5) else lights.each do |light| light.on = options[:on] if !options[:on].nil? light.set_state(options[:color]) if !options[:color].nil? - sleep(0.5) + sleep(0.5) end end end