philips_hue 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- philips_hue (0.1.6)
4
+ philips_hue (0.1.7)
5
5
  httparty (>= 0.10.0)
6
6
  json (>= 1.6)
7
7
 
data/bin/flash.rb CHANGED
@@ -16,6 +16,7 @@ options = OpenStruct.new
16
16
  options.light_id = 1
17
17
  options.delay = 1
18
18
  options.repeat = 1
19
+ options.crazy = false
19
20
  options.color = colors["red"]
20
21
  options.app_name = "lightsapp"
21
22
  options.api_url = "192.168.1.14"
@@ -40,16 +41,17 @@ OptionParser.new do |opts|
40
41
  opts.on("-n [num]", "--repeat [num]", Integer, "Repeat [num] times") do |num|
41
42
  options.repeat = num
42
43
  end
44
+ opts.on("-z", "--crazymode", "Enable crazymode") do |crazy|
45
+ options.crazy = crazy
46
+ end
43
47
  end.parse!
44
48
 
45
49
  # get everything ready...
46
50
  hue = PhilipsHue::Bridge.new(options.app_name, options.api_url)
47
51
  light = hue.light(options.light_id)
48
- old_xy = light.xy
49
52
 
50
53
  # ...make magic happen
51
- options.repeat.times do
52
- # flash!
53
- light.flash(options.color, :delay => options.delay, :old_xy => old_xy)
54
- sleep options.delay
54
+ options.repeat.times do |n|
55
+ light.flash(options.color, options.delay, options.crazy)
56
+ sleep options.delay unless n == options.repeat-1
55
57
  end
@@ -162,14 +162,60 @@ module PhilipsHue
162
162
  end
163
163
 
164
164
  # flash a specified color
165
- # if you're flashing multiple times, specify :old_xy to minimize API calls
166
- def flash(xy, options = {})
167
- old_xy = options[:old_xy] || self.xy
168
- delay = options[:delay] || 1
169
- self.xy = xy
165
+ # xy is the color to use
166
+ # delay is the length of the flash (in seconds)
167
+ # crazymode causes the light to blink during the flash
168
+ def flash(xy, delay = 1, crazymode = false)
169
+ # use state() and set() to minimize number of API calls
170
+ original = self.state
171
+
172
+ # turns the light on and maxes brightness too
173
+ flash_state = {
174
+ :xy => xy,
175
+ :on => true,
176
+ :bri => 255
177
+ }
178
+
179
+ # blink repeatedly if crazymode flag is set
180
+ # (works best for delay >2 seconds)
181
+ flash_state["alert"] = "lselect" if crazymode
182
+
183
+ # the state to which to restore
184
+ # (color gets set after)
185
+ final_state = {
186
+ :on => original["on"],
187
+ :bri => original["bri"],
188
+ :alert => original["alert"]
189
+ }
190
+
191
+ # smartly return to the original color
192
+ case original["colormode"]
193
+ when "xy"
194
+ final_state[:xy] = original["xy"]
195
+ when "ct"
196
+ final_state[:ct] = original["ct"]
197
+ when "hs"
198
+ final_state[:hue] = original["hue"]
199
+ end
200
+
201
+ # flash!
202
+ set(flash_state)
203
+ # zzz...
170
204
  sleep delay
171
- self.xy = old_xy
172
- end
205
+ # restore the light to its original state
206
+ set(final_state)
207
+ end
208
+
209
+ # handy aliases
210
+ alias_method :brightness, :bri
211
+ alias_method :brightness=, :bri=
212
+ alias_method :mode, :colormode
213
+ alias_method :saturation, :sat
214
+ alias_method :saturation=, :sat=
215
+ alias_method :temperature, :ct
216
+ alias_method :temperature=, :ct=
217
+ alias_method :color_temperature, :ct
218
+ alias_method :color_temperature=, :ct=
173
219
 
174
220
  # pretty-print the light's status
175
221
  def to_s
@@ -1,3 +1,3 @@
1
1
  module PhilipsHue
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philips_hue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty