Module: PhilipsHue::Helpers

Included in:
Light
Defined in:
lib/philips_hue/helpers.rb

Instance Method Summary collapse

Instance Method Details

flash repeatedly



25
26
27
# File 'lib/philips_hue/helpers.rb', line 25

def blink
  self.alert = "lselect"
end

#blipObject

flash once



20
21
22
# File 'lib/philips_hue/helpers.rb', line 20

def blip
  self.alert = "select"
end

#blueObject



11
12
13
# File 'lib/philips_hue/helpers.rb', line 11

def blue
  self.xy = [0.1727, 0.0512]
end

#flash(xy, delay = 1, crazymode = false) ⇒ Object

flash a specified color

xy is the color to use
delay is the length of the flash (in seconds)
crazymode causes the light to blink during the flash


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/philips_hue/helpers.rb', line 33

def flash(xy, delay = 1, crazymode = false)
  # use state() and set() to minimize number of API calls
  original = self.state

  # turns the light on and maxes brightness too
  flash_state = {
    :xy  => xy,
    :on  => true,
    :bri => 255
  }

  # blink instead if the color is not going to change
  if xy == original["xy"] && original["colormode"] == "xy"
    flash_state["alert"] = "select"
  end

  # blink repeatedly if crazymode flag is set
  # (works best for delay >2 seconds)
  flash_state["alert"] = "lselect" if crazymode

  # the state to which to restore
  # (color gets set after)
  final_state = {
    :on => original["on"],
    :bri => original["bri"],
    :alert => original["alert"]
  }

  # smartly return to the original color
  case original["colormode"]
  when "xy"
    final_state[:xy]  = original["xy"]
  when "ct"
    final_state[:ct]  = original["ct"]
  when "hs"
    final_state[:hue] = original["hue"]
  end

  # flash!
  set(flash_state)
  # zzz...
  sleep delay
  # restore the light to its original state
  set(final_state)
end

#greenObject



7
8
9
# File 'lib/philips_hue/helpers.rb', line 7

def green
  self.xy = [0.4034, 0.5067]
end

#redObject



3
4
5
# File 'lib/philips_hue/helpers.rb', line 3

def red
  self.xy = [0.6446, 0.3289]
end

#yellowObject



15
16
17
# File 'lib/philips_hue/helpers.rb', line 15

def yellow
  self.xy = [0.4447, 0.4918]
end