lights 0.8.11 → 0.8.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/lights +68 -4
- data/lib/lights.rb +25 -3
- data/lib/lights/exception.rb +6 -0
- data/lib/lights/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmRlODZhMWNjYzYyY2Y3ZWU4M2M4NmI0MzNjYWFmOTZlOTFmNWViNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWI3MDc4ZmZlZjI1OWEyNTBjYjcwMTJmZGRhOTg2ZmQ0M2U1YTY5YQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2NjYzcwMjA1M2Y0NmI4OTY5MmZiYTdjMjU1ZWFhNWQ3ZTFhNWMxN2U2YTM0
|
10
|
+
YmFkMDBkYzhjNjA3ODA2ZWE4NmExOWZmZDY3OTYzZGJkOTMzMmFhNmE5YTRl
|
11
|
+
NWQzMzU2NGNhYmY3MDJiOGNjNmFkM2QwYWU4NjkwNzA3M2FkYTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzA4YWNlZWZmZTMwZWI4NDIyM2ZhZjM0NjY0Yzg0YjQ0MmY3YWVmODFkY2Qy
|
14
|
+
NWIwMWU5ZTc3MzBmNjM4OGEyNTFkY2ExODM1NzlkNWQxZmU4ZTJhMzE3MDgz
|
15
|
+
ODQzZmY0OTJlZDY0MTkyNzdiODE3OGQxMWUxN2RmNmM1ZjFiMDU=
|
data/bin/lights
CHANGED
@@ -92,11 +92,59 @@ class LightsCli
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
def
|
95
|
+
def edit
|
96
96
|
type = ARGV.shift
|
97
97
|
hue = Lights.new @config["bridge_ip"], @config["username"]
|
98
98
|
options = {}
|
99
99
|
|
100
|
+
case type
|
101
|
+
when "light"
|
102
|
+
id = ARGV.shift
|
103
|
+
if !id
|
104
|
+
puts "Must specify light id."
|
105
|
+
exit 1
|
106
|
+
end
|
107
|
+
|
108
|
+
OptionParser.new do |opts|
|
109
|
+
opts.on("--name", "--name <name>", String, "Set light name"){|n| options[:name]=n}
|
110
|
+
end.parse!
|
111
|
+
if !options[:name]
|
112
|
+
puts "Must specify new light name."
|
113
|
+
exit 1
|
114
|
+
end
|
115
|
+
|
116
|
+
light = Bulb.new(id,{"name"=>options[:name]})
|
117
|
+
hue.edit_bulb light
|
118
|
+
when "group"
|
119
|
+
id = ARGV.shift
|
120
|
+
if !id
|
121
|
+
puts "Must specify group id."
|
122
|
+
exit 1
|
123
|
+
end
|
124
|
+
|
125
|
+
OptionParser.new do |opts|
|
126
|
+
opts.on("--name", "--name <name>", String, "Set light name"){|n| options[:name]=n}
|
127
|
+
opts.on("-l", "--lights 1,2,...N", Array, "Which lights to put in group"){|l| options[:lights]=l}
|
128
|
+
end.parse!
|
129
|
+
if !options[:name] && !options[:lights]
|
130
|
+
puts "Must specify a value to edit."
|
131
|
+
exit 1
|
132
|
+
end
|
133
|
+
group = Group.new(id)
|
134
|
+
group.name = options[:name] if options[:name]
|
135
|
+
group.lights = options[:lights] if options[:lights]
|
136
|
+
hue.edit_group group
|
137
|
+
when nil
|
138
|
+
STDERR.puts "Must specify a type to edit."
|
139
|
+
else
|
140
|
+
STDERR.puts "Don't know how to edit type \"#{type}\"."
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def delete
|
145
|
+
type = ARGV.shift
|
146
|
+
hue = Lights.new @config["bridge_ip"], @config["username"]
|
147
|
+
|
100
148
|
case type
|
101
149
|
when "group"
|
102
150
|
id = ARGV.shift
|
@@ -132,17 +180,18 @@ class LightsCli
|
|
132
180
|
options = {}
|
133
181
|
OptionParser.new do |opts|
|
134
182
|
opts.on("-j", "--json", "Print JSON response"){|j| options[:json] = j}
|
183
|
+
opts.on("-n", "--new", "Only list new"){|n| options[:new] = n}
|
135
184
|
end.parse!
|
136
185
|
|
137
186
|
type = ARGV.shift
|
138
187
|
case type
|
139
188
|
when nil, "","lights"
|
140
|
-
response = hue.request_bulb_list
|
189
|
+
response = options[:new] ? hue.request_new_bulb_list : hue.request_bulb_list
|
141
190
|
response.each{|id,value| objects << hue.request_bulb_info( id )}
|
142
191
|
titles = ["ID","NAME"]
|
143
192
|
methods = [:id,:name]
|
144
193
|
when "sensors"
|
145
|
-
response = hue.request_sensor_list
|
194
|
+
response = options[:new] ? hue.request_new_sensor_list : hue.request_sensor_list
|
146
195
|
response.each { |id,value| objects << hue.request_sensor_info( id )}
|
147
196
|
titles = ["ID","NAME"]
|
148
197
|
methods = [:id,:name]
|
@@ -305,6 +354,16 @@ class LightsCli
|
|
305
354
|
end
|
306
355
|
end
|
307
356
|
|
357
|
+
def search
|
358
|
+
lights = Lights.new @config["bridge_ip"], @config["username"]
|
359
|
+
response = lights.search_new
|
360
|
+
if response.first["success"]
|
361
|
+
puts "Started search."
|
362
|
+
else
|
363
|
+
puts "Unknown error. Did not begin search."
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
308
367
|
private
|
309
368
|
def set_bulb_state(state,bulbs)
|
310
369
|
lights = Lights.new @config["bridge_ip"], @config["username"]
|
@@ -343,7 +402,7 @@ end
|
|
343
402
|
|
344
403
|
|
345
404
|
if !ARGV[0]
|
346
|
-
STDERR.puts "Must specify a command. (config, list, register, discover, on, off, set, create, delete)"
|
405
|
+
STDERR.puts "Must specify a command. (config, list, register, discover, search, on, off, set, create, edit, delete)"
|
347
406
|
exit 1
|
348
407
|
end
|
349
408
|
|
@@ -370,11 +429,16 @@ begin
|
|
370
429
|
cli.create
|
371
430
|
elsif command == "delete"
|
372
431
|
cli.delete
|
432
|
+
elsif command == "edit"
|
433
|
+
cli.edit
|
434
|
+
elsif command == "search"
|
435
|
+
cli.search
|
373
436
|
else
|
374
437
|
puts "Cannot find command #{command}."
|
375
438
|
end
|
376
439
|
rescue BridgeConnectException,
|
377
440
|
UsernameException,
|
441
|
+
ResourceUnavailableException,
|
378
442
|
BulbStateValueOutOfRangeException,
|
379
443
|
BulbStateValueTypeException => e
|
380
444
|
puts e.message
|
data/lib/lights.rb
CHANGED
@@ -57,10 +57,22 @@ class Lights
|
|
57
57
|
@bulbs << Bulb.new( id, bulb_data )
|
58
58
|
end
|
59
59
|
|
60
|
+
def search_new
|
61
|
+
post "lights"
|
62
|
+
end
|
63
|
+
|
60
64
|
def request_bulb_list
|
61
65
|
get "lights"
|
62
66
|
end
|
63
67
|
|
68
|
+
def request_new_bulb_list
|
69
|
+
get "lights/new"
|
70
|
+
end
|
71
|
+
|
72
|
+
def request_new_sensor_list
|
73
|
+
get "sensors/new"
|
74
|
+
end
|
75
|
+
|
64
76
|
def request_bulb_info( id )
|
65
77
|
response = get "lights/#{id}"
|
66
78
|
Bulb.new(id,response)
|
@@ -124,6 +136,14 @@ class Lights
|
|
124
136
|
delete "groups/#{id}"
|
125
137
|
end
|
126
138
|
|
139
|
+
def edit_bulb( bulb )
|
140
|
+
put "lights/#{bulb.id}", bulb
|
141
|
+
end
|
142
|
+
|
143
|
+
def edit_group( group )
|
144
|
+
put "groups/#{group.id}", group
|
145
|
+
end
|
146
|
+
|
127
147
|
def delete_user( username )
|
128
148
|
delete "config/whitelist/#{username}"
|
129
149
|
end
|
@@ -134,10 +154,12 @@ private
|
|
134
154
|
case type
|
135
155
|
when 1
|
136
156
|
raise UsernameException
|
157
|
+
when 3
|
158
|
+
raise ResourceUnavailableException, result["error"]["description"]
|
137
159
|
when 101
|
138
160
|
raise BridgeConnectException
|
139
161
|
else
|
140
|
-
|
162
|
+
raise "Unknown Error: #{result["error"]["description"]}"
|
141
163
|
end
|
142
164
|
end
|
143
165
|
|
@@ -154,7 +176,7 @@ private
|
|
154
176
|
result
|
155
177
|
end
|
156
178
|
|
157
|
-
def put( path, data )
|
179
|
+
def put( path, data={} )
|
158
180
|
@logger.debug "==> PUT: #{path}"
|
159
181
|
@logger.debug data.to_json
|
160
182
|
response = @http.put( "/api/#{@username}/#{path}", data.to_json )
|
@@ -163,7 +185,7 @@ private
|
|
163
185
|
JSON.parse response.body
|
164
186
|
end
|
165
187
|
|
166
|
-
def post( path, data )
|
188
|
+
def post( path, data={} )
|
167
189
|
@logger.debug "==> POST: #{path}"
|
168
190
|
@logger.debug data.to_json
|
169
191
|
response = @http.post( "/api/#{@username}/#{path}", data.to_json )
|
data/lib/lights/exception.rb
CHANGED
data/lib/lights/version.rb
CHANGED