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 +1 -1
- data/bin/flash.rb +7 -5
- data/lib/philips_hue/light.rb +53 -7
- data/lib/philips_hue/version.rb +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
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
|
-
|
53
|
-
|
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
|
data/lib/philips_hue/light.rb
CHANGED
@@ -162,14 +162,60 @@ module PhilipsHue
|
|
162
162
|
end
|
163
163
|
|
164
164
|
# flash a specified color
|
165
|
-
#
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
172
|
-
|
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
|
data/lib/philips_hue/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|