lights 0.8.20 → 0.9.1
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 +4 -4
- data/README.md +1 -2
- data/bin/lights +15 -8
- data/lib/lights.rb +14 -5
- data/lib/lights/version.rb +1 -1
- data/lights.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d6d774f2b47f0ba0dec8353e1476ec9ac3366e3
|
4
|
+
data.tar.gz: e84a70cc13a7a783bb993839618cffc15b9d243d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de9aca5aa3201622e69735a6625b104756165af6b951894adbe457a3503773896b5b12eb64110fae3366188027078c4b7d370bef6115157f278c7def134ea7fe
|
7
|
+
data.tar.gz: f73fa4c4d4284e7f12ec2e9c91a3d685d899db59c95a3d64bc125792b1c98c13cf516ed7262f13972ef21211f3a9007910c6955160d40a4aeffb3bd13bdc2538
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Basic Usage
|
|
16
16
|
```ruby
|
17
17
|
require 'lights'
|
18
18
|
client = Lights.new( '192.168.x.x', 'username' )
|
19
|
-
client.
|
19
|
+
client.register
|
20
20
|
client.request_bulb_list
|
21
21
|
```
|
22
22
|
See [lights-examples](https://github.com/turnerba/lights-examples) for more usage examples.
|
@@ -26,7 +26,6 @@ CLI Quick Setup
|
|
26
26
|
|
27
27
|
```
|
28
28
|
lights discover -s
|
29
|
-
lights config -f --user <username>
|
30
29
|
lights register
|
31
30
|
lights list
|
32
31
|
lights on
|
data/bin/lights
CHANGED
@@ -18,18 +18,22 @@ class LightsCli
|
|
18
18
|
def configured?
|
19
19
|
@config["username"] && @config["bridge_ip"]
|
20
20
|
end
|
21
|
+
|
22
|
+
def ip_configured?
|
23
|
+
@config["bridge_ip"]
|
24
|
+
end
|
21
25
|
|
22
26
|
def config
|
23
27
|
options = {}
|
24
28
|
OptionParser.new do |opts|
|
25
|
-
opts.on("-u", "--user <username>", String, "Username"){|url| options[:user]=url}
|
26
29
|
opts.on("-i", "--ip <bridge ip>", String, "Bridge ip address"){|ip| options[:ip]=ip}
|
27
30
|
opts.on("-f", "--force", "Force write to config file"){|f| options[:force]=f}
|
28
31
|
opts.on("-l", "--list", "List saved configuration settings") {|l| options[:list]=l}
|
29
32
|
end.parse!
|
30
33
|
|
31
|
-
|
32
|
-
puts "
|
34
|
+
unless options[:ip] || options[:list]
|
35
|
+
puts "usage:"
|
36
|
+
puts " #{File.basename(__FILE__)} config (--ip <bridge IP> | --list)"
|
33
37
|
exit 1
|
34
38
|
end
|
35
39
|
|
@@ -52,7 +56,6 @@ class LightsCli
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
|
-
@config["username"] = options[:user] || @config["username"]
|
56
59
|
@config["bridge_ip"] = options[:ip] || @config["bridge_ip"]
|
57
60
|
|
58
61
|
write_config
|
@@ -263,7 +266,9 @@ class LightsCli
|
|
263
266
|
|
264
267
|
def register
|
265
268
|
lights = Lights.new @config["bridge_ip"], @config["username"]
|
266
|
-
response = lights.
|
269
|
+
response = lights.register
|
270
|
+
@config["username"] = lights.username
|
271
|
+
write_config
|
267
272
|
end
|
268
273
|
|
269
274
|
def discover
|
@@ -447,12 +452,14 @@ begin
|
|
447
452
|
cli.config
|
448
453
|
elsif command == "discover"
|
449
454
|
cli.discover
|
455
|
+
elsif !cli.ip_configured?
|
456
|
+
puts "Please run 'lights discover -s' or 'lights config --ip <IP>' before using."
|
457
|
+
elsif command == "register"
|
458
|
+
cli.register
|
450
459
|
elsif !cli.configured?
|
451
|
-
puts "Please run 'lights
|
460
|
+
puts "Please run 'lights register' before using."
|
452
461
|
elsif command == "list"
|
453
462
|
cli.list
|
454
|
-
elsif command == "register"
|
455
|
-
cli.register
|
456
463
|
elsif command == "on"
|
457
464
|
cli.on
|
458
465
|
elsif command == "off"
|
data/lib/lights.rb
CHANGED
@@ -12,8 +12,8 @@ require 'lights/loggerconfig'
|
|
12
12
|
|
13
13
|
class Lights
|
14
14
|
|
15
|
-
attr_reader :bulbs
|
16
|
-
def initialize(ip,username)
|
15
|
+
attr_reader :bulbs, :username
|
16
|
+
def initialize(ip,username=nil)
|
17
17
|
@ip = ip
|
18
18
|
@username = username
|
19
19
|
@http = Net::HTTP.new(ip,80)
|
@@ -40,16 +40,21 @@ class Lights
|
|
40
40
|
@bridges
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
data = { "devicetype"=>"lights"
|
45
|
-
"username"=>@username }
|
43
|
+
def register
|
44
|
+
data = { "devicetype"=>"lights" }
|
46
45
|
response = @http.post "/api", data.to_json
|
47
46
|
result = JSON.parse(response.body).first
|
48
47
|
if result.has_key? "error"
|
49
48
|
process_error result
|
49
|
+
elsif result["success"]
|
50
|
+
@username = result["success"]["username"]
|
50
51
|
end
|
52
|
+
result
|
51
53
|
end
|
52
54
|
|
55
|
+
# backwards compatibility
|
56
|
+
alias_method :register_username, :register
|
57
|
+
|
53
58
|
def request_config
|
54
59
|
get "config"
|
55
60
|
end
|
@@ -172,6 +177,7 @@ private
|
|
172
177
|
|
173
178
|
def get( path )
|
174
179
|
@logger.debug "==> GET: #{path}"
|
180
|
+
raise UsernameException unless @username
|
175
181
|
request = Net::HTTP::Get.new( "/api/#{@username}/#{path}" )
|
176
182
|
response = @http.request request
|
177
183
|
result = JSON.parse( response.body )
|
@@ -185,6 +191,7 @@ private
|
|
185
191
|
|
186
192
|
def put( path, data={} )
|
187
193
|
@logger.debug "==> PUT: #{path}"
|
194
|
+
raise UsernameException unless @username
|
188
195
|
@logger.debug data.to_json
|
189
196
|
response = @http.put( "/api/#{@username}/#{path}", data.to_json )
|
190
197
|
result = JSON.parse( response.body )
|
@@ -198,6 +205,7 @@ private
|
|
198
205
|
|
199
206
|
def post( path, data={} )
|
200
207
|
@logger.debug "==> POST: #{path}"
|
208
|
+
raise UsernameException unless @username
|
201
209
|
@logger.debug data.to_json
|
202
210
|
response = @http.post( "/api/#{@username}/#{path}", data.to_json )
|
203
211
|
result = JSON.parse( response.body )
|
@@ -211,6 +219,7 @@ private
|
|
211
219
|
|
212
220
|
def delete( path )
|
213
221
|
@logger.debug "==> DELETE: #{path}"
|
222
|
+
raise UsernameException unless @username
|
214
223
|
request = Net::HTTP::Delete.new( "/api/#{@username}/#{path}" )
|
215
224
|
response = @http.request request
|
216
225
|
result = JSON.parse( response.body )
|
data/lib/lights/version.rb
CHANGED
data/lights.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = "lights"
|
13
13
|
s.homepage = 'http://rubygems.org/gems/lights'
|
14
14
|
s.license = 'MIT'
|
15
|
-
s.date = '
|
15
|
+
s.date = '2015-12-15'
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split($/)
|
18
18
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lights
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brady Turner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simpletable
|