Skip to content

Commit

Permalink
Merge pull request #1 from zachfeldman/master
Browse files Browse the repository at this point in the history
Update Sarkonovich fork
  • Loading branch information
sarkonovich committed Apr 10, 2015
2 parents cea20ab + d182640 commit e6f5221
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
1 change: 1 addition & 0 deletions server/modules/google_calendar/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 31 additions & 11 deletions server/modules/hue/module.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
require 'hue'
require 'color.rb'


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

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 = []

# 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
Expand Down Expand Up @@ -84,13 +100,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?
sleep(0.5)
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)
MODULE_INSTANCES.push(AlexaHue.new)

0 comments on commit e6f5221

Please sign in to comment.