lifx_dash 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +10 -0
- data/.simplecov +10 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +17 -0
- data/CODE_OF_CONDUCT.md +50 -0
- data/CONTRIBUTING.md +31 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +235 -0
- data/Rakefile +38 -0
- data/bin/console +14 -0
- data/bin/lifx_dash +112 -0
- data/bin/setup +11 -0
- data/features/lifx_dash.feature +17 -0
- data/features/step_definitions/lifx_dash_steps.rb +4 -0
- data/features/support/env.rb +1 -0
- data/lib/lifx_dash.rb +13 -0
- data/lib/lifx_dash/capturer.rb +37 -0
- data/lib/lifx_dash/configuration.rb +68 -0
- data/lib/lifx_dash/daemonizer.rb +39 -0
- data/lib/lifx_dash/lifx_http_api.rb +72 -0
- data/lib/lifx_dash/monitor.rb +31 -0
- data/lib/lifx_dash/snoop.rb +20 -0
- data/lib/lifx_dash/version.rb +3 -0
- data/lifx_dash.gemspec +66 -0
- data/man/lifx_dash.1 +170 -0
- data/man/lifx_dash.1.html +217 -0
- data/man/lifx_dash.1.ronn +115 -0
- data/test/lifx_dash/lifx_http_api_test.rb +73 -0
- data/test/test_helper.rb +15 -0
- metadata +251 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
lifx_dash(1) -- Toggle LIFX lights with an Amazon Dash button
|
2
|
+
=============================================================
|
3
|
+
|
4
|
+
## SYNOPSIS
|
5
|
+
|
6
|
+
`lifx_dash` `monitor` -m DASH_MAC_ADDRESS -t LIFX_API_TOKEN<br>
|
7
|
+
`lifx_dash` `snoop`<br>
|
8
|
+
`lifx_dash` `config`
|
9
|
+
|
10
|
+
## DESCRIPTION
|
11
|
+
|
12
|
+
**lifx_dash** is a simple command-line tool to monitor your network for Amazon
|
13
|
+
Dash button presses and toggle LIFX lights ON and OFF. The tool provides two
|
14
|
+
commands, `monitor` and `snoop`.
|
15
|
+
|
16
|
+
Use `snoop` to listen for Dash presses on your network, and identify the
|
17
|
+
button's MAC address.
|
18
|
+
|
19
|
+
Use `monitor` (with a MAC address and LIFX HTTP API token) to respond to
|
20
|
+
presses, and toggle your lights ON and OFF. You can optionally pass a bulb
|
21
|
+
selector, or choose to daemonize the `monitor` process.
|
22
|
+
|
23
|
+
A `config` command also exists, allowing you to set default options for
|
24
|
+
`monitor` and `snoop`.
|
25
|
+
|
26
|
+
## REQUIREMENTS
|
27
|
+
|
28
|
+
`lifx_dash` requires at least one LIFX bulb, and any Amazon Dash button. You
|
29
|
+
will also need a wifi network and root access to sniff packets on your network
|
30
|
+
adaptor.
|
31
|
+
|
32
|
+
Follow Amazon's Dash button setup steps, but **stop** before choosing any
|
33
|
+
particular product to purchase. You aill also need a free LIFX API token from
|
34
|
+
here: [https://cloud.lifx.com/settings](https://cloud.lifx.com/settings)
|
35
|
+
|
36
|
+
## OPTIONS
|
37
|
+
|
38
|
+
The snoop command has one optional flag, the network interface to listen on.
|
39
|
+
|
40
|
+
* `-i`, `--iface=arg`: Network Interface (default: en0)
|
41
|
+
|
42
|
+
Wait for the network to quiet down, before pressing the button, since other
|
43
|
+
devices may respond with ARP packets of their own when you press. Take care to
|
44
|
+
choose the MAC address from the ARP packet that occurs only once from a single
|
45
|
+
MAC address.
|
46
|
+
|
47
|
+
The `monitor` command accepts the following flags, both a mac address and api
|
48
|
+
token are required.
|
49
|
+
|
50
|
+
* `-m`, `--mac-address=arg`: Dash button MAC Address (required)
|
51
|
+
* `-t`, `--token=arg`: LIFX HTTP API Token (required)
|
52
|
+
* `-s`, `--selector=arg`: LIFX Bulb Selector (default: all)
|
53
|
+
* `-i`, `--iface=arg`: Network Interface (default: en0)
|
54
|
+
* `-d`, `--[no-]daemonize`: Dameonize the monitor process (default: no)
|
55
|
+
* `-l`, `--log-file`: Log file location (when running as a daemon) (default: /tmp/lifx_dash.log)
|
56
|
+
|
57
|
+
## EXAMPLES
|
58
|
+
|
59
|
+
Get help on command options and arguments
|
60
|
+
|
61
|
+
$ lifx_dash -h
|
62
|
+
$ lifx_dash monitor -h
|
63
|
+
$ lifx_dash snoop --help
|
64
|
+
|
65
|
+
Snoop for Dash button presses on en1
|
66
|
+
|
67
|
+
$ lifx_dash snoop en1
|
68
|
+
|
69
|
+
Monitor Dash button presses on en0 with DASH_MAC_ADDRESS and LIFX_API_TOKEN,
|
70
|
+
when pressed, toggle all lights
|
71
|
+
|
72
|
+
$ lifx_dash monitor -t LIFX_API_TOKEN -m DASH_MAC_ADDRESS
|
73
|
+
|
74
|
+
Monitor Dash button presses on en1 with a DASH_MAC_ADDRESS and LIFX_API_TOKEN,
|
75
|
+
when pressed toggle the light with id 'd3b2f2d97459'
|
76
|
+
|
77
|
+
$ lifx_dash monitor --token=LIFX_API_TOKEN --mac-address=DASH_MAC_ADDRESS -s 'd3b2f2d97459' -i en1
|
78
|
+
|
79
|
+
Show the current configuration file options
|
80
|
+
|
81
|
+
$ lifx_dash config -s
|
82
|
+
|
83
|
+
## FILES
|
84
|
+
|
85
|
+
Use the `config` command to set values for the command options. These will be
|
86
|
+
saved to: ~/.lifx_dash.rc.yml and used as defaults. They can still be overridden
|
87
|
+
by any arguments passed on the command line.
|
88
|
+
|
89
|
+
If running as a daemon (-d switch), the `lifx_dash monitor` command will log to
|
90
|
+
`/tmp/lifx_dash.log` by default. Use the --log-file flag to override this.
|
91
|
+
|
92
|
+
## BUGS
|
93
|
+
|
94
|
+
No known bugs. Please report issues here:
|
95
|
+
[https://github.com/matthutchinson/lifx_dash/issues](https://github.com/matthutchinson/lifx_dash/issues)
|
96
|
+
|
97
|
+
## LICENSE
|
98
|
+
|
99
|
+
The MIT License:
|
100
|
+
[https://raw.githubusercontent.com/matthutchinson/lifx_dash/master/LICENSE.txt](https://raw.githubusercontent.com/matthutchinson/lifx_dash/master/LICENSE.txt)
|
101
|
+
|
102
|
+
## COPYRIGHT
|
103
|
+
|
104
|
+
Copyright (c) 2016 Matthew Hutchinson
|
105
|
+
|
106
|
+
## AUTHOR
|
107
|
+
|
108
|
+
Matthew Hutchinson, [https://matthewhutchinson.net](https://matthewhutchinson.net)
|
109
|
+
|
110
|
+
## SEE ALSO
|
111
|
+
|
112
|
+
* [https://rubygems.org/gems/lifx_dash](https://rubygems.org/gems/lifx_dash)
|
113
|
+
* [https://github.com/matthutchinson/lifx_dash](https://github.com/matthutchinson/lifx_dash)
|
114
|
+
* [https://cloud.lifx.com/settings](https://cloud.lifx.com/settings)
|
115
|
+
* [http://tinyurl.com/zujfkjs](http://tinyurl.com/zujfkjs)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+'/../test_helper')
|
2
|
+
|
3
|
+
class TestLifxHTTPApi < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@logger = MiniTest::Mock.new
|
7
|
+
@api_client = LifxDash::LifxHTTPApi.new('my-token', @logger)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_toggles_lights_logging_successful
|
11
|
+
selector = "d073d500ec8e"
|
12
|
+
body = { results: [{ id: "d073d500ec8e", label: "Golden Boy", status: "ok" } ]}.to_json
|
13
|
+
stub_request(:post, lifx_url(selector)).to_return(body: body, status: 207)
|
14
|
+
|
15
|
+
@logger.expect(:info, nil, ["Toggling lights! (via #{LifxDash::LifxHTTPApi::BASE_URI})"])
|
16
|
+
@logger.expect(:info, nil, ["Lights toggled successfully!"])
|
17
|
+
@logger.expect(:info, nil, ["API reply (207): #{body}"])
|
18
|
+
@api_client.toggle(selector)
|
19
|
+
|
20
|
+
assert @logger.verify
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_toggles_lights_logging_warnings
|
24
|
+
selector = "all"
|
25
|
+
http_responses = {
|
26
|
+
401 => { error: "Invalid token" }, # invalid token in header
|
27
|
+
500 => nil, # server issue
|
28
|
+
207 => "{}" # server OK, but results not present
|
29
|
+
}
|
30
|
+
|
31
|
+
http_responses.each do |code, api_response_body|
|
32
|
+
stub_request(:post, lifx_url(selector)).
|
33
|
+
to_return(body: api_response_body.to_json, status: code)
|
34
|
+
|
35
|
+
@logger.expect(:info, nil, ["Toggling lights! (via #{LifxDash::LifxHTTPApi::BASE_URI})"])
|
36
|
+
@logger.expect(:warn, nil, ["Warning: Possible issue with LIFX lights or HTTP API response"])
|
37
|
+
@logger.expect(:warn, nil, ["API reply (#{code}): #{api_response_body.to_json}"])
|
38
|
+
@api_client.toggle(selector)
|
39
|
+
|
40
|
+
assert @logger.verify
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_raises_error_on_toggle_when_http_errors
|
45
|
+
assert_raises(Errno::ECONNRESET) do
|
46
|
+
@logger.expect(:info, nil, ["Toggling lights! (via #{LifxDash::LifxHTTPApi::BASE_URI})"])
|
47
|
+
@logger.expect(:error, nil, ["Error: POST request to #{LifxDash::LifxHTTPApi::BASE_URI} failed: Connection reset by peer"])
|
48
|
+
|
49
|
+
net_error = -> (uri) { raise Errno::ECONNRESET.new }
|
50
|
+
Net::HTTP::Post.stub :new, net_error do
|
51
|
+
@api_client.toggle('all')
|
52
|
+
end
|
53
|
+
|
54
|
+
assert @logger.verify
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_raises_error_on_toggle_with_bad_selector
|
59
|
+
assert_raises(URI::InvalidURIError) do
|
60
|
+
bad_selector = "im a bad bulb selector"
|
61
|
+
@logger.expect(:error, nil, ["Error: POST request to #{LifxDash::LifxHTTPApi::BASE_URI} failed: bad URI(is not URI?): #{lifx_url(bad_selector)}"])
|
62
|
+
@api_client.toggle(bad_selector)
|
63
|
+
|
64
|
+
assert @logger.verify
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def lifx_url(selector)
|
71
|
+
"https://#{LifxDash::LifxHTTPApi::BASE_URI}/lights/#{selector}/toggle"
|
72
|
+
end
|
73
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
if ENV['COVERAGE']
|
2
|
+
if ENV['TRAVIS']
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
else
|
6
|
+
require 'simplecov'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'lifx_dash'
|
11
|
+
require 'minitest/autorun'
|
12
|
+
require 'webmock/minitest'
|
13
|
+
|
14
|
+
# set a quiet logger to /dev/null
|
15
|
+
LOGGER = Logger.new("/dev/null")
|
metadata
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lifx_dash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Hutchinson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gli
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.14.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.14.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: packetfu
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.11
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.11
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ronn
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rdoc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: aruba
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: coveralls
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: |2
|
168
|
+
A command line tool to listen for Amazon Dash button presses and toggle LIFX
|
169
|
+
lights ON and OFF (via the LIFX HTTP API). With options to configure: the Dash
|
170
|
+
MAC address, network interface and LIFX bulb selector. Inspired by Ted
|
171
|
+
Benson's hack (http://tinyurl.com/zba3da2). Root access is required for
|
172
|
+
network packet sniffing.
|
173
|
+
email:
|
174
|
+
- matt@hiddenloop.com
|
175
|
+
executables:
|
176
|
+
- lifx_dash
|
177
|
+
extensions: []
|
178
|
+
extra_rdoc_files:
|
179
|
+
- README.md
|
180
|
+
- LICENSE.txt
|
181
|
+
files:
|
182
|
+
- ".coveralls.yml"
|
183
|
+
- ".gitignore"
|
184
|
+
- ".simplecov"
|
185
|
+
- ".travis.yml"
|
186
|
+
- CHANGELOG.md
|
187
|
+
- CODE_OF_CONDUCT.md
|
188
|
+
- CONTRIBUTING.md
|
189
|
+
- Gemfile
|
190
|
+
- LICENSE.txt
|
191
|
+
- README.md
|
192
|
+
- Rakefile
|
193
|
+
- bin/console
|
194
|
+
- bin/lifx_dash
|
195
|
+
- bin/setup
|
196
|
+
- features/lifx_dash.feature
|
197
|
+
- features/step_definitions/lifx_dash_steps.rb
|
198
|
+
- features/support/env.rb
|
199
|
+
- lib/lifx_dash.rb
|
200
|
+
- lib/lifx_dash/capturer.rb
|
201
|
+
- lib/lifx_dash/configuration.rb
|
202
|
+
- lib/lifx_dash/daemonizer.rb
|
203
|
+
- lib/lifx_dash/lifx_http_api.rb
|
204
|
+
- lib/lifx_dash/monitor.rb
|
205
|
+
- lib/lifx_dash/snoop.rb
|
206
|
+
- lib/lifx_dash/version.rb
|
207
|
+
- lifx_dash.gemspec
|
208
|
+
- man/lifx_dash.1
|
209
|
+
- man/lifx_dash.1.html
|
210
|
+
- man/lifx_dash.1.ronn
|
211
|
+
- test/lifx_dash/lifx_http_api_test.rb
|
212
|
+
- test/test_helper.rb
|
213
|
+
homepage: http://github.com/matthutchinson/lifx_dash
|
214
|
+
licenses:
|
215
|
+
- MIT
|
216
|
+
metadata:
|
217
|
+
allowed_push_host: https://rubygems.org
|
218
|
+
post_install_message:
|
219
|
+
rdoc_options:
|
220
|
+
- "--title"
|
221
|
+
- lifx_dash
|
222
|
+
- "--main"
|
223
|
+
- README.md
|
224
|
+
- "-ri"
|
225
|
+
require_paths:
|
226
|
+
- lib
|
227
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
228
|
+
requirements:
|
229
|
+
- - ">="
|
230
|
+
- !ruby/object:Gem::Version
|
231
|
+
version: 2.0.0
|
232
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
requirements:
|
238
|
+
- an Amazon Dash button
|
239
|
+
- one or more LIFX bulbs
|
240
|
+
- root (sudo) access
|
241
|
+
rubyforge_project:
|
242
|
+
rubygems_version: 2.2.2
|
243
|
+
signing_key:
|
244
|
+
specification_version: 4
|
245
|
+
summary: Toggle LIFX lights with an Amazon Dash button
|
246
|
+
test_files:
|
247
|
+
- features/lifx_dash.feature
|
248
|
+
- features/step_definitions/lifx_dash_steps.rb
|
249
|
+
- features/support/env.rb
|
250
|
+
- test/lifx_dash/lifx_http_api_test.rb
|
251
|
+
- test/test_helper.rb
|