class Lita::Handlers::HueLightswitch
Public Instance Methods
demo()
click to toggle source
# File lib/lita/handlers/hue_lightswitch.rb, line 88 def demo light.demo end
handle_hue(message)
click to toggle source
Split the captured hue command into a one-word command name
and everything after that (if anything) and pass the results on to the :hue_execute mapping below.
# File lib/lita/handlers/hue_lightswitch.rb, line 25 def handle_hue(message) command, *rest = message.matches.last.last.split response = hue_execute(command, rest) message.reply response end
hue_execute(command, rest=[])
click to toggle source
START:mapping Given a one-word hue :command and a possibly-empty array of
additional parameters :rest, step through this case statement and perform the first matching action.
# File lib/lita/handlers/hue_lightswitch.rb, line 36 def hue_execute(command, rest=[]) case command when 'demo' demo 'Enjoy the light demo!' when 'list_colors' list_colors when 'color' recolor rest "Setting color to #{rest.join ' '}" when 'off' off! "Turning off light!" when 'on' on! "Turning on light!" else debug_message = [command, rest].flatten.join ' ' "I don't know how to [#{debug_message}] a hue bulb." end end
light()
click to toggle source
Create a reusable instance variable handle to a bulb
named 'Bloom' (or whatever your config value for :hue_bulb_name is set to.
# File lib/lita/handlers/hue_lightswitch.rb, line 12 def light @_light ||= HueColoredBulb.new(config.hue_bulb_name) end
list_colors()
click to toggle source
START:colors Simple help text in case someone forgets Lita's `hue` commands
# File lib/lita/handlers/hue_lightswitch.rb, line 61 def list_colors light.colors.join ' ' end
off!()
click to toggle source
START:basics
These three commands are pass-throughs to the HueColoredBulb
wrapper.
# File lib/lita/handlers/hue_lightswitch.rb, line 80 def off! light.off! end
on!()
click to toggle source
# File lib/lita/handlers/hue_lightswitch.rb, line 84 def on! light.on! end
recolor(rest)
click to toggle source
Set the bulb's color to one of the named colors it recognizes
e.g. red, green, blue, etc.
# File lib/lita/handlers/hue_lightswitch.rb, line 67 def recolor(rest) new_color = rest.first light.set_color new_color end