lifx-http 0.2.0 → 0.2.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/Gemfile.lock +4 -0
- data/README.md +18 -1
- data/bin/lifx-http +20 -1
- data/lib/lifx-http.rb +13 -2
- data/lib/lifx-http/version.rb +1 -1
- data/lifx-http.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e29919953e3e6acd75b01192501cbe27b9ea8a5
|
|
4
|
+
data.tar.gz: 02eb463c51e547216c7595d29d3d5a9cc2a64a87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c094f36d028a0d47238a28f95ce763a958e40123cd1f63d7a3df132fa382521fce1d4e14110a39dfa70e3486c7bf4446652e48508238e954d99919991172a0b
|
|
7
|
+
data.tar.gz: a0da9499d9e0a7dc75e01bb27a697a33cf591106c9805d9dbe664b9a220e6151947f9be0d3280b79405ef4febaf64bdcc097366eec26f1027062a280bd8ce56a
|
data/Gemfile.lock
CHANGED
|
@@ -6,6 +6,7 @@ PATH
|
|
|
6
6
|
grape-entity (~> 0.4)
|
|
7
7
|
grape-swagger (~> 0.7)
|
|
8
8
|
lifx (= 0.4.5)
|
|
9
|
+
mdns (>= 0.1.1)
|
|
9
10
|
rack (~> 1.5)
|
|
10
11
|
rack-cors (~> 0.2)
|
|
11
12
|
|
|
@@ -57,9 +58,12 @@ GEM
|
|
|
57
58
|
configatron (~> 3.0)
|
|
58
59
|
timers (~> 1.0)
|
|
59
60
|
yell (~> 2.0)
|
|
61
|
+
mdns (0.1.1)
|
|
62
|
+
net-dns (~> 0.8)
|
|
60
63
|
minitest (4.7.5)
|
|
61
64
|
multi_json (1.9.2)
|
|
62
65
|
multi_xml (0.5.5)
|
|
66
|
+
net-dns (0.8.0)
|
|
63
67
|
rack (1.5.2)
|
|
64
68
|
rack-accept (0.4.5)
|
|
65
69
|
rack (>= 0.4)
|
data/README.md
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
This is an **unofficial** JSON RESTful API service for controlling LIFX devices. This API adds some reliability that the [LIFX gem](https://github.com/LIFX/lifx-gem) does not include.
|
|
6
6
|
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
* Mostly synchronous, apart from setting colour
|
|
10
|
+
* Supports MDNS
|
|
11
|
+
|
|
7
12
|
## Requirements
|
|
8
13
|
|
|
9
14
|
* Ruby 2.0+
|
|
@@ -19,7 +24,8 @@ This is an **unofficial** JSON RESTful API service for controlling LIFX devices.
|
|
|
19
24
|
* URL params: `curl -XPUT http://localhost:56780/lights/all/color?hue=120&saturation=1&brightness=1&duration=2 -d ''`
|
|
20
25
|
* JSON body: `curl -XPUT http://localhost:56780/lights/all/color -H "Content-Type: application/json" -d '{"hue": 120, "saturation": 1, "brightness": 1, "duration":2}'`
|
|
21
26
|
* Override method by setting `_method`: `curl http://localhost:56780/lights/all/color?hue=120&saturation=1&brightness=1&duration=2&_method=put`
|
|
22
|
-
|
|
27
|
+
* Start a slow sunrise effect:
|
|
28
|
+
* `curl -XPUT http://localhost:56780/lights/all/color?hue=35&saturation=0.37&brightness=0.65&duration=10m -d ''`
|
|
23
29
|
|
|
24
30
|
## API
|
|
25
31
|
|
|
@@ -46,6 +52,17 @@ To view documentation and play with the API, start the API server locally, then
|
|
|
46
52
|
You should see something like this:
|
|
47
53
|

|
|
48
54
|
|
|
55
|
+
## Changelog
|
|
56
|
+
|
|
57
|
+
#### 0.2.1
|
|
58
|
+
|
|
59
|
+
- Duration now supports minute and hour suffixes e.g. "12h" for 12 hours thanks to @Bluebie
|
|
60
|
+
- MDNS support! Enables easy discovery of a LIFX HTTP instance on the LAN.
|
|
61
|
+
|
|
62
|
+
#### 0.2.0
|
|
63
|
+
|
|
64
|
+
- First gem release
|
|
65
|
+
|
|
49
66
|
## License
|
|
50
67
|
|
|
51
68
|
MIT. See [LICENSE](LICENSE)
|
data/bin/lifx-http
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
|
|
2
3
|
require "lifx-http"
|
|
3
4
|
require "rack/cors"
|
|
4
5
|
require "lifx-http/method_override"
|
|
5
6
|
require "webrick"
|
|
6
7
|
require "optparse"
|
|
8
|
+
require "mdns"
|
|
7
9
|
|
|
8
10
|
options = {
|
|
9
|
-
port: 56780
|
|
11
|
+
port: 56780,
|
|
12
|
+
mdns_host: "lifx-http",
|
|
13
|
+
mdns_ip: begin
|
|
14
|
+
Socket.ip_address_list.find { |ip| ip.ipv4_private? }.ip_address
|
|
15
|
+
end
|
|
10
16
|
}
|
|
17
|
+
|
|
11
18
|
OptionParser.new do |parser|
|
|
12
19
|
parser.banner = "Usage: lifx-http [options]"
|
|
13
20
|
parser.version = LIFXHTTP::VERSION
|
|
14
21
|
parser.on("-p PORT", "--port PORT", "Specify the port to run lifx-http on. Defaults to #{options[:port]}") do |port|
|
|
15
22
|
options[:port] = port.to_i
|
|
16
23
|
end
|
|
24
|
+
parser.on("--hostname HOSTNAME", "Specify the host the MDNS broadcast should use. Defaults to #{options[:mdns_host]}") do |host|
|
|
25
|
+
options[:mdns_host] = host
|
|
26
|
+
end
|
|
27
|
+
parser.on("--ip MDNS_IP", "Specify the IP the MDNS record should resolve to. Defaults to #{options[:mdns_ip]}") do |ip|
|
|
28
|
+
options[:mdns_ip] = ip
|
|
29
|
+
end
|
|
17
30
|
end.parse!
|
|
18
31
|
|
|
19
32
|
app = Rack::Builder.new do
|
|
@@ -28,4 +41,10 @@ app = Rack::Builder.new do
|
|
|
28
41
|
run LIFXHTTP::API
|
|
29
42
|
end
|
|
30
43
|
|
|
44
|
+
if options[:mdns_ip]
|
|
45
|
+
MDNS.add_record("#{options[:mdns_host]}.local. 120 A #{options[:mdns_ip]}")
|
|
46
|
+
MDNS.start
|
|
47
|
+
puts "LIFX HTTP can be reached at http://#{options[:mdns_host]}:#{options[:port]}/"
|
|
48
|
+
end
|
|
49
|
+
|
|
31
50
|
Rack::Handler::WEBrick.run(app, Port: options[:port])
|
data/lib/lifx-http.rb
CHANGED
|
@@ -133,7 +133,7 @@ module LIFXHTTP
|
|
|
133
133
|
requires :saturation, type: Float, desc: "Saturation: 0-1"
|
|
134
134
|
requires :brightness, type: Float, desc: "Brightness: 0-1"
|
|
135
135
|
optional :kelvin, type: Integer, default: 3_500, desc: "Kelvin: 2500-10000. Defaults to 3500"
|
|
136
|
-
optional :duration, type:
|
|
136
|
+
optional :duration, type: String, default: '1', desc: "Duration in seconds. Defaults to 1.0. Suffix with m or h to specify minutes or hours. For example, 10m"
|
|
137
137
|
end
|
|
138
138
|
put :color do
|
|
139
139
|
color = LIFX::Color.hsbk(
|
|
@@ -142,7 +142,18 @@ module LIFXHTTP
|
|
|
142
142
|
params[:brightness],
|
|
143
143
|
params[:kelvin]
|
|
144
144
|
)
|
|
145
|
-
|
|
145
|
+
|
|
146
|
+
# parse minute and hour duration forms
|
|
147
|
+
duration = case params[:duration]
|
|
148
|
+
when /m$/i # Minutes
|
|
149
|
+
params[:duration].to_f * 60
|
|
150
|
+
when /h$/i # Hours
|
|
151
|
+
params[:duration].to_f * 60 * 60
|
|
152
|
+
else
|
|
153
|
+
params[:duration].to_f
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
lifx.sync { 3.times { @target.set_color(color, duration: duration) } } # Retry
|
|
146
157
|
present_target(@target)
|
|
147
158
|
end
|
|
148
159
|
end
|
data/lib/lifx-http/version.rb
CHANGED
data/lifx-http.gemspec
CHANGED
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.add_dependency "rack", "~> 1.5"
|
|
23
23
|
spec.add_dependency "rack-cors", "~> 0.2"
|
|
24
24
|
spec.add_dependency "lifx", "= 0.4.5"
|
|
25
|
+
spec.add_dependency "mdns", ">= 0.1.1"
|
|
25
26
|
spec.add_dependency "grape", "~> 0.6"
|
|
26
27
|
spec.add_dependency "grape-entity", "~> 0.4"
|
|
27
28
|
spec.add_dependency "grape-swagger", "~> 0.7"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lifx-http
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jack Chen (chendo)
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-03-
|
|
11
|
+
date: 2014-03-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - '='
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: 0.4.5
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: mdns
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.1.1
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.1.1
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: grape
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|