Class: Lita::Handlers::HueLightswitch

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/hue_lightswitch.rb

Instance Method Summary collapse

Instance Method Details

#demoObject



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(message)
	command, *rest = message.matches.last.last.split
	response = hue_execute(command, rest)
	message.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
    debug_message = [command, rest].flatten.join ' '
	  "I don't know how to [#{debug_message}] a hue bulb."
	end
end

#lightObject

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_colorsObject

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