ledenet_api 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -2
- data/README.md +17 -10
- data/bin/ledenet-ufo +121 -0
- data/ledenet_api.gemspec +3 -2
- data/lib/ledenet/api.rb +4 -0
- data/lib/ledenet/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 784967fa26bb47506ffea3842a1cbb919a8d12e1
|
4
|
+
data.tar.gz: 509d3fa070c8a72efd913aaf7bcda83f709e61a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebe124461916180dd20440aedd240af67888d67b16dff70703012d489d410525611f5c8ea566d4841b4c34746d69dcb49a821d692939f026f475e92303e787be
|
7
|
+
data.tar.gz: 79a0575d4dd38f3dee97b3c1116fafb070ab55f7564f500b3b9bf526922aac9690e14b02ac7442b4741abbde351147f714358e852fdf4e7917f887f91e93453b
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ledenet_api (
|
5
|
-
bindata (>=
|
4
|
+
ledenet_api (1.1.0)
|
5
|
+
bindata (>= 2.3)
|
6
|
+
ipaddress (>= 0.8)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
11
|
bindata (2.3.0)
|
11
12
|
diff-lcs (1.2.5)
|
13
|
+
ipaddress (0.8.3)
|
12
14
|
rake (10.4.2)
|
13
15
|
rspec (3.3.0)
|
14
16
|
rspec-core (~> 3.3.0)
|
data/README.md
CHANGED
@@ -74,27 +74,34 @@ To turn the controller on and off:
|
|
74
74
|
|
75
75
|
```ruby
|
76
76
|
api.on
|
77
|
-
=> true
|
78
77
|
api.off
|
79
|
-
=> true
|
80
78
|
```
|
81
79
|
|
82
|
-
### Color
|
80
|
+
### Color / Warm White
|
83
81
|
|
84
|
-
To get the current color
|
82
|
+
To get the current color settings:
|
85
83
|
|
86
84
|
```ruby
|
87
|
-
api.
|
88
|
-
=>
|
85
|
+
api.current_color_data
|
86
|
+
#=> {:red=>255, :green=>255, :blue=>255, :warm_white=>255}
|
87
|
+
api.current_rgb
|
88
|
+
#=> [255, 255, 255]
|
89
|
+
api.current_warm_white
|
90
|
+
#=> 255
|
89
91
|
```
|
90
92
|
|
91
93
|
To set the color:
|
92
94
|
|
93
95
|
```ruby
|
94
|
-
api.
|
95
|
-
|
96
|
+
api.update_rgb(255, 0, 255)
|
97
|
+
|
98
|
+
api.update_warm_white(100)
|
96
99
|
```
|
97
100
|
|
98
|
-
|
101
|
+
You can also update individual parameters:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
api.update_color_data(red: 100)
|
99
105
|
|
100
|
-
|
106
|
+
api.update_color_data(blue: 255, warm_white: 0)
|
107
|
+
```
|
data/bin/ledenet-ufo
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
require 'ledenet_api'
|
7
|
+
require 'ipaddress'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
|
11
|
+
banner = <<-BANNER
|
12
|
+
Usage: ledenet-ufo --list
|
13
|
+
OR: ledenet-ufo [IP|HW ADDR] [OPTIONS]
|
14
|
+
|
15
|
+
BANNER
|
16
|
+
|
17
|
+
if ARGV.count > 0 && !ARGV.first.start_with?('-')
|
18
|
+
arg = ARGV.shift
|
19
|
+
|
20
|
+
if IPAddress.valid?(arg)
|
21
|
+
options[:ip] = arg
|
22
|
+
elsif /^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/i.match(arg)
|
23
|
+
options[:hw_addr] = arg
|
24
|
+
else
|
25
|
+
raise "Invalid device speicifier \"#{arg}\". Must be ip or mac address."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
opts = OptionParser.new do |opts|
|
30
|
+
opts.banner = banner
|
31
|
+
|
32
|
+
opts.on("-r", "--red [VALUE]", Integer, "Set red to VALUE") do |v|
|
33
|
+
options[:red] = v
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("-g", "--green [VALUE]", Integer, "Set green to VALUE") do |v|
|
37
|
+
options[:green] = v
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("-b", "--blue [VALUE]", Integer, "Set blue to VALUE") do |v|
|
41
|
+
options[:blue] = v
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on("-w", "--warm-white [VALUE]", Integer, "Set warm white to VALUE") do |v|
|
45
|
+
options[:warm_white] = v
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on("--on", "Turn on the controller") do |v|
|
49
|
+
options[:on?] = true
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on("--off", "Turn off the controller") do
|
53
|
+
options[:on?] = false
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on("-l", "--list", Integer, "Prints a list of available devices and exists") do |v|
|
57
|
+
options[:list] = true
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on("-s", "--status", "Prints status as JSON") do |v|
|
61
|
+
options[:print_status?] = true
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on("-h", "--help", "Prints this help message") do
|
65
|
+
options[:print_help?] = true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.parse!
|
70
|
+
|
71
|
+
if options[:print_help?]
|
72
|
+
puts opts
|
73
|
+
exit 0
|
74
|
+
end
|
75
|
+
|
76
|
+
begin
|
77
|
+
if options[:list]
|
78
|
+
if options.count > 1
|
79
|
+
warn "--list is incompatible with other options!\n\n"
|
80
|
+
warn opts
|
81
|
+
exit 1
|
82
|
+
end
|
83
|
+
|
84
|
+
devices = LEDENET.discover_devices(expected_devices: 1000)
|
85
|
+
|
86
|
+
row_format = "%16s %18s %20s\n"
|
87
|
+
printf row_format, "IP ADDRESS", "HW ADDRESS", "Model #"
|
88
|
+
|
89
|
+
LEDENET.discover_devices.each do |device|
|
90
|
+
printf row_format, device.ip, device.hw_addr, device.model
|
91
|
+
end
|
92
|
+
else
|
93
|
+
ip = nil
|
94
|
+
if options[:ip]
|
95
|
+
ip = options[:ip]
|
96
|
+
elsif options[:hw_addr]
|
97
|
+
r = LEDENET.discover_devices.select { |x| x.hw_addr == options[:hw_addr] }
|
98
|
+
if r.empty?
|
99
|
+
raise "Couldn't find device with mac addr: #{options[:hw_addr]}"
|
100
|
+
end
|
101
|
+
ip = r.first.ip
|
102
|
+
else
|
103
|
+
ip = LEDENET.discover_devices.first.ip
|
104
|
+
end
|
105
|
+
|
106
|
+
api = LEDENET::Api.new(ip)
|
107
|
+
|
108
|
+
api.set_power(options[:on?]) unless options[:on?].nil?
|
109
|
+
api.update_color_data(options.select { |k,_| %w{red green blue warm_white}.include?(k.to_s) })
|
110
|
+
|
111
|
+
if options[:print_status?]
|
112
|
+
status = api.current_color_data
|
113
|
+
status = status.merge(is_on: api.on?)
|
114
|
+
|
115
|
+
puts status.to_json
|
116
|
+
end
|
117
|
+
end
|
118
|
+
rescue Exception => e
|
119
|
+
puts "Error: #{e}"
|
120
|
+
puts e.backtrace.join("\n")
|
121
|
+
end
|
data/ledenet_api.gemspec
CHANGED
@@ -14,11 +14,12 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir = "
|
18
|
-
spec.executables =
|
17
|
+
spec.bindir = "bin"
|
18
|
+
spec.executables = ["ledenet-ufo"]
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency 'bindata', '>= 2.3'
|
22
|
+
spec.add_dependency 'ipaddress', '>= 0.8'
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.10"
|
24
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/ledenet/api.rb
CHANGED
data/lib/ledenet/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledenet_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Mullins
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ipaddress
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,7 +83,8 @@ dependencies:
|
|
69
83
|
description:
|
70
84
|
email:
|
71
85
|
- chris@sidoh.org
|
72
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- ledenet-ufo
|
73
88
|
extensions: []
|
74
89
|
extra_rdoc_files: []
|
75
90
|
files:
|
@@ -79,6 +94,7 @@ files:
|
|
79
94
|
- LICENSE.txt
|
80
95
|
- README.md
|
81
96
|
- Rakefile
|
97
|
+
- bin/ledenet-ufo
|
82
98
|
- ledenet_api.gemspec
|
83
99
|
- lib/ledenet/api.rb
|
84
100
|
- lib/ledenet/device_discovery.rb
|