lights 0.8.16 → 0.8.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/bin/lights +8 -2
- data/lib/lights.rb +18 -3
- data/lib/lights/exception.rb +6 -0
- data/lib/lights/groupstate.rb +24 -0
- data/lib/lights/version.rb +1 -1
- data/spec/groupstate_spec.rb +29 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDBiNzRiZTg2NjE1ZmI3ZmY1OTMwZmUzY2E2MmYwOWVjMTM1YWRjMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzBmOGUyODgzNWIyMWNlYzc1MmM0YTllY2MyN2ExZWZhZTY0NmRiMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWM5ZTQ3OTllZTk1YmRjZDljN2I5ZmQxYTFmMGRiYTc1OTMzZDczZTlhOGFh
|
10
|
+
MDA2ZTRjYWI4ZWUxYTAzMzY2NWU1NWQ2YWFkZjA1MTU0OWZjOGZkNmViNTVk
|
11
|
+
NTIyMDdhMWI4MzhmY2E5ODFkZmQ2OGE3M2Q1YTgyYmRiN2M1YjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWQ3ODQzNGM3NzQ4YzM5NzFjMGE4ZGM4NzBhMDgzNDUwYmMwNTgxNDc0NzNh
|
14
|
+
NGNmNmJkMDc2Y2FhYTllM2Y0MTEwZTAwZjk1ZGY4NDg4NDE1OTg1ZTM1YzBh
|
15
|
+
N2FkZGVhNTdhM2Y4MDdmMTlhNzY4YmJhYmYyZDY4ZThhMGYwMTc=
|
data/bin/lights
CHANGED
@@ -293,6 +293,7 @@ class LightsCli
|
|
293
293
|
opts.on("-z", "--xy x,y", Array, "Set xy"){|z| options[:xy]=z}
|
294
294
|
opts.on("-l", "--lights 1,2,...N", Array, "Which lights to control"){|l| options[:lights]=l}
|
295
295
|
opts.on("-g", "--groups 1,2,...N", Array, "Which groups to control"){|g| options[:groups]=g}
|
296
|
+
opts.on("-S", "--scene <id>", String, "Which scene to recall"){|s| options[:scene]=s}
|
296
297
|
opts.on("-d", "--duration seconds", OptionParser::DecimalInteger, "Transition duration in seconds"){|d| options[:duration]=d}
|
297
298
|
end.parse!
|
298
299
|
|
@@ -301,7 +302,8 @@ class LightsCli
|
|
301
302
|
&& !options[:ct] && !options[:brightness] \
|
302
303
|
&& !options[:hue] && !options[:saturation] \
|
303
304
|
&& !options[:effect] && !options[:alert] \
|
304
|
-
&& !options[:xy] && !options[:color]
|
305
|
+
&& !options[:xy] && !options[:color] \
|
306
|
+
&& !options[:scene]
|
305
307
|
puts "Must specify a state to set."
|
306
308
|
bad_args = true
|
307
309
|
end
|
@@ -312,7 +314,7 @@ class LightsCli
|
|
312
314
|
end
|
313
315
|
exit 1 if bad_args
|
314
316
|
|
315
|
-
s =
|
317
|
+
s = GroupState.new
|
316
318
|
if options[:on]
|
317
319
|
s.on = true
|
318
320
|
elsif options[:off]
|
@@ -350,6 +352,9 @@ class LightsCli
|
|
350
352
|
if options[:xy]
|
351
353
|
s.xy = options[:xy]
|
352
354
|
end
|
355
|
+
if options[:scene]
|
356
|
+
s.scene = options[:scene]
|
357
|
+
end
|
353
358
|
|
354
359
|
if options[:lights]
|
355
360
|
set_bulb_state(s,options[:lights])
|
@@ -442,6 +447,7 @@ begin
|
|
442
447
|
rescue BridgeConnectException,
|
443
448
|
UsernameException,
|
444
449
|
ResourceUnavailableException,
|
450
|
+
ParameterUnavailableException,
|
445
451
|
BulbStateValueOutOfRangeException,
|
446
452
|
BulbStateValueTypeException => e
|
447
453
|
puts e.message
|
data/lib/lights.rb
CHANGED
@@ -7,6 +7,7 @@ require 'json'
|
|
7
7
|
require 'lights/bridge'
|
8
8
|
require 'lights/exception'
|
9
9
|
require 'lights/datastore'
|
10
|
+
require 'lights/groupstate'
|
10
11
|
require 'lights/loggerconfig'
|
11
12
|
|
12
13
|
class Lights
|
@@ -156,6 +157,8 @@ private
|
|
156
157
|
raise UsernameException
|
157
158
|
when 3
|
158
159
|
raise ResourceUnavailableException, result["error"]["description"]
|
160
|
+
when 6
|
161
|
+
raise ParameterUnavailableException, result["error"]["description"]
|
159
162
|
when 101
|
160
163
|
raise BridgeConnectException
|
161
164
|
else
|
@@ -180,27 +183,39 @@ private
|
|
180
183
|
@logger.debug "==> PUT: #{path}"
|
181
184
|
@logger.debug data.to_json
|
182
185
|
response = @http.put( "/api/#{@username}/#{path}", data.to_json )
|
186
|
+
result = JSON.parse( response.body )
|
183
187
|
@logger.debug "<== #{response.code}"
|
184
188
|
@logger.debug response.body
|
185
|
-
|
189
|
+
if result.first.kind_of?(Hash) && result.first.has_key?("error")
|
190
|
+
process_error result.first
|
191
|
+
end
|
192
|
+
result
|
186
193
|
end
|
187
194
|
|
188
195
|
def post( path, data={} )
|
189
196
|
@logger.debug "==> POST: #{path}"
|
190
197
|
@logger.debug data.to_json
|
191
198
|
response = @http.post( "/api/#{@username}/#{path}", data.to_json )
|
199
|
+
result = JSON.parse( response.body )
|
192
200
|
@logger.debug "<== #{response.code}"
|
193
201
|
@logger.debug response.body
|
194
|
-
|
202
|
+
if result.first.kind_of?(Hash) && result.first.has_key?("error")
|
203
|
+
process_error result.first
|
204
|
+
end
|
205
|
+
result
|
195
206
|
end
|
196
207
|
|
197
208
|
def delete( path )
|
198
209
|
@logger.debug "==> DELETE: #{path}"
|
199
210
|
request = Net::HTTP::Delete.new( "/api/#{@username}/#{path}" )
|
200
211
|
response = @http.request request
|
212
|
+
result = JSON.parse( response.body )
|
201
213
|
@logger.debug "<== #{response.code}"
|
202
214
|
@logger.debug response.body
|
203
|
-
|
215
|
+
if result.first.kind_of?(Hash) && result.first.has_key?("error")
|
216
|
+
process_error result.first
|
217
|
+
end
|
218
|
+
result
|
204
219
|
end
|
205
220
|
|
206
221
|
end
|
data/lib/lights/exception.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'lights/bulbstate'
|
2
|
+
|
3
|
+
class GroupState < BulbState
|
4
|
+
attr_reader :scene
|
5
|
+
def initialize(data={})
|
6
|
+
super(data)
|
7
|
+
set_scene data["scene"] if data["scene"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def scene=(value) set_scene(value) end
|
11
|
+
def set_scene(value)
|
12
|
+
if value.class == String
|
13
|
+
@scene = value
|
14
|
+
else
|
15
|
+
raise BulbStateValueTypeException, "Scene value has incorrect type. Requires String, got #{value.class}. Was #{value.inspect}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def data
|
20
|
+
data = BulbState.instance_method(:data).bind(self).call
|
21
|
+
data["scene"] = @scene if @scene
|
22
|
+
data
|
23
|
+
end
|
24
|
+
end
|
data/lib/lights/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'lights'
|
2
|
+
|
3
|
+
describe GroupState do
|
4
|
+
|
5
|
+
it "properly reconstructs object hash" do
|
6
|
+
data = { "scene" => "22978db88-on-0" }
|
7
|
+
s = GroupState.new(data)
|
8
|
+
s.data.should eql data
|
9
|
+
end
|
10
|
+
|
11
|
+
# SCENE
|
12
|
+
it "should properly set scene value in constructor" do
|
13
|
+
data = { "scene" => "22978db88-on-0" }
|
14
|
+
s = GroupState.new(data)
|
15
|
+
s.scene.should eql "22978db88-on-0"
|
16
|
+
s.data["scene"].should eql "22978db88-on-0"
|
17
|
+
end
|
18
|
+
it "should properly set scene value" do
|
19
|
+
s = GroupState.new
|
20
|
+
s.scene = "22978db88-on-0"
|
21
|
+
s.scene.should eq "22978db88-on-0"
|
22
|
+
s.data["scene"].should eq "22978db88-on-0"
|
23
|
+
end
|
24
|
+
it "should raise exception when scene has invalid type" do
|
25
|
+
s = GroupState.new
|
26
|
+
expect { s.scene = 124 }.to raise_error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lights
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brady Turner
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/lights/exception.rb
|
119
119
|
- lib/lights/group.rb
|
120
120
|
- lib/lights/grouplist.rb
|
121
|
+
- lib/lights/groupstate.rb
|
121
122
|
- lib/lights/hobject.rb
|
122
123
|
- lib/lights/list.rb
|
123
124
|
- lib/lights/loggerconfig.rb
|
@@ -140,6 +141,7 @@ files:
|
|
140
141
|
- spec/features/lights.feature
|
141
142
|
- spec/features/support/setup.rb
|
142
143
|
- spec/group_spec.rb
|
144
|
+
- spec/groupstate_spec.rb
|
143
145
|
- spec/rule_spec.rb
|
144
146
|
- spec/scene_spec.rb
|
145
147
|
homepage: http://rubygems.org/gems/lights
|
@@ -174,5 +176,6 @@ test_files:
|
|
174
176
|
- spec/features/lights.feature
|
175
177
|
- spec/features/support/setup.rb
|
176
178
|
- spec/group_spec.rb
|
179
|
+
- spec/groupstate_spec.rb
|
177
180
|
- spec/rule_spec.rb
|
178
181
|
- spec/scene_spec.rb
|