Class: Lita::Handlers::HueLightswitch
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::HueLightswitch
- Defined in:
- lib/lita/handlers/hue_lightswitch.rb
Instance Method Summary collapse
- #demo ⇒ Object
-
#handle_hue(message) ⇒ Object
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.
-
#hue_execute(command, rest = []) ⇒ Object
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.
-
#light ⇒ Object
Create a reusable instance variable handle to a bulb named ‘Bloom’ (or whatever your config value for :hue_bulb_name is set to..
-
#list_colors ⇒ Object
START:colors Simple help text in case someone forgets Lita’s ‘hue` commands.
-
#off! ⇒ Object
START:basics.
- #on! ⇒ Object
-
#recolor(rest) ⇒ Object
Set the bulb’s color to one of the named colors it recognizes e.g.
Instance Method Details
#demo ⇒ Object
88 89 90 |
# File 'lib/lita/handlers/hue_lightswitch.rb', line 88 def demo light.demo end |
#handle_hue(message) ⇒ Object
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.
25 26 27 28 29 |
# File 'lib/lita/handlers/hue_lightswitch.rb', line 25 def handle_hue() command, *rest = .matches.last.last.split response = hue_execute(command, rest) .reply response end |
#hue_execute(command, rest = []) ⇒ Object
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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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 = [command, rest].flatten.join ' ' "I don't know how to [#{}] a hue bulb." end end |
#light ⇒ Object
Create a reusable instance variable handle to a bulb
named 'Bloom' (or whatever your config value for
:hue_bulb_name is set to.
12 13 14 |
# File 'lib/lita/handlers/hue_lightswitch.rb', line 12 def light @_light ||= HueColoredBulb.new(config.hue_bulb_name) end |
#list_colors ⇒ Object
START:colors Simple help text in case someone forgets Lita’s ‘hue` commands
61 62 63 |
# File 'lib/lita/handlers/hue_lightswitch.rb', line 61 def list_colors light.colors.join ' ' end |
#off! ⇒ Object
START:basics
These three commands are pass-throughs to the HueColoredBulb wrapper.
80 81 82 |
# File 'lib/lita/handlers/hue_lightswitch.rb', line 80 def off! light.off! end |
#on! ⇒ Object
84 85 86 |
# File 'lib/lita/handlers/hue_lightswitch.rb', line 84 def on! light.on! end |
#recolor(rest) ⇒ Object
Set the bulb’s color to one of the named colors it recognizes
e.g. red, green, blue, etc.
67 68 69 70 |
# File 'lib/lita/handlers/hue_lightswitch.rb', line 67 def recolor(rest) new_color = rest.first light.set_color new_color end |