lifx 0.4.0 → 0.4.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/.yardopts +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +7 -1
- data/lib/bindata_ext/bool.rb +1 -0
- data/lib/lifx/firmware.rb +1 -0
- data/lib/lifx/gateway_connection.rb +1 -0
- data/lib/lifx/light.rb +9 -4
- data/lib/lifx/light_collection.rb +2 -0
- data/lib/lifx/logging.rb +2 -1
- data/lib/lifx/message.rb +0 -1
- data/lib/lifx/network_context.rb +5 -0
- data/lib/lifx/observable.rb +1 -0
- data/lib/lifx/protocol/device.rb +1 -1
- data/lib/lifx/protocol/light.rb +1 -1
- data/lib/lifx/protocol/payload.rb +1 -1
- data/lib/lifx/protocol/sensor.rb +1 -1
- data/lib/lifx/protocol/wan.rb +1 -1
- data/lib/lifx/protocol/wifi.rb +1 -1
- data/lib/lifx/protocol_path.rb +1 -0
- data/lib/lifx/routing_manager.rb +1 -0
- data/lib/lifx/routing_table.rb +1 -0
- data/lib/lifx/seen.rb +8 -0
- data/lib/lifx/tag_manager.rb +1 -0
- data/lib/lifx/target.rb +1 -2
- data/lib/lifx/timers.rb +1 -0
- data/lib/lifx/transport/tcp.rb +1 -0
- data/lib/lifx/transport/udp.rb +1 -0
- data/lib/lifx/utilities.rb +1 -0
- data/lib/lifx/version.rb +1 -1
- data/spec/integration/client_spec.rb +5 -5
- 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: e976d2a6d1ab56351ef47fbae89e84a1c08c98ed
|
4
|
+
data.tar.gz: 2f8d52787abf6aee8dd809e3f61ac2395c0c8225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49dd808c6baabd1d07a15e355e6367a272af8ef40c2469b3db1475a648e52ae5a4ef59c17395903825ac4ca42ee247e07c126bddda40804d0c0201d6592200ba
|
7
|
+
data.tar.gz: 2123ea65a1c2f246ab93c0c81532bc774de9669540bb312c7e3ec0a71b34e67dd6bca51b9faeb8fb3cd97575b4b2651248b691628fbac9cd6d716e69333d28d4
|
data/.yardopts
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@ This gem is in an early beta state. Expect breaking API changes.
|
|
19
19
|
Add this line to your application's Gemfile:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
gem 'lifx'
|
22
|
+
gem 'lifx'
|
23
23
|
```
|
24
24
|
|
25
25
|
And then execute:
|
@@ -28,6 +28,12 @@ And then execute:
|
|
28
28
|
$ bundle
|
29
29
|
```
|
30
30
|
|
31
|
+
Or install the gem with:
|
32
|
+
|
33
|
+
```shell
|
34
|
+
gem install lifx
|
35
|
+
```
|
36
|
+
|
31
37
|
## Usage
|
32
38
|
|
33
39
|
```ruby
|
data/lib/bindata_ext/bool.rb
CHANGED
data/lib/lifx/firmware.rb
CHANGED
data/lib/lifx/light.rb
CHANGED
@@ -51,6 +51,7 @@ module LIFX
|
|
51
51
|
# Adds a block to be run when a payload of class `payload_class` is received
|
52
52
|
# @param payload_class [Class] Payload type to execute block on
|
53
53
|
# @param &hook [Proc] Hook to run
|
54
|
+
# @api private
|
54
55
|
# @return [void]
|
55
56
|
def add_hook(payload_class, hook_arg = nil, &hook_block)
|
56
57
|
hook = block_given? ? hook_block : hook_arg
|
@@ -63,6 +64,7 @@ module LIFX
|
|
63
64
|
# Removes a hook added by {#add_hook}
|
64
65
|
# @param payload_class [Class] Payload type to delete hook from
|
65
66
|
# @param hook [Proc] The original hook passed into {#add_hook}
|
67
|
+
# @api private
|
66
68
|
# @return [void]
|
67
69
|
def remove_hook(payload_class, hook)
|
68
70
|
@message_hooks[payload_class].delete(hook)
|
@@ -132,14 +134,16 @@ module LIFX
|
|
132
134
|
set_power!(0)
|
133
135
|
end
|
134
136
|
|
137
|
+
# @see #power
|
135
138
|
# @return [Boolean] Returns true if device is on
|
136
|
-
def on?(
|
137
|
-
power(
|
139
|
+
def on?(refresh: false, fetch: true)
|
140
|
+
power(refresh: refresh, fetch: fetch) == :on
|
138
141
|
end
|
139
142
|
|
143
|
+
# @see #power
|
140
144
|
# @return [Boolean] Returns true if device is off
|
141
|
-
def off?(
|
142
|
-
power(
|
145
|
+
def off?(refresh: false, fetch: true)
|
146
|
+
power(refresh: refresh, fetch: fetch) == :off
|
143
147
|
end
|
144
148
|
|
145
149
|
# @param refresh: see #label
|
@@ -322,6 +326,7 @@ module LIFX
|
|
322
326
|
end
|
323
327
|
|
324
328
|
# Returns a nice string representation of the Light
|
329
|
+
# @return [String]
|
325
330
|
def to_s
|
326
331
|
%Q{#<LIFX::Light id=#{id} label=#{label(fetch: false)} power=#{power(fetch: false)}>}.force_encoding(Encoding.default_external)
|
327
332
|
end
|
@@ -83,12 +83,14 @@ module LIFX
|
|
83
83
|
DEFAULT_ALIVE_THRESHOLD = 30 # seconds
|
84
84
|
# Returns an Array of {Light}s considered alive
|
85
85
|
# @param threshold: The maximum number of seconds a {Light} was last seen to be considered alive
|
86
|
+
# @return [Array<Light>] Lights considered alive
|
86
87
|
def alive(threshold: DEFAULT_ALIVE_THRESHOLD)
|
87
88
|
lights.select { |l| l.seconds_since_seen <= threshold }
|
88
89
|
end
|
89
90
|
|
90
91
|
# Returns an Array of {Light}s considered stale
|
91
92
|
# @param threshold: The minimum number of seconds since a {Light} was last seen to be considered stale
|
93
|
+
# @return [Array<Light>] Lights considered stale
|
92
94
|
def stale(threshold: DEFAULT_ALIVE_THRESHOLD)
|
93
95
|
lights.select { |l| l.seconds_since_seen > threshold }
|
94
96
|
end
|
data/lib/lifx/logging.rb
CHANGED
data/lib/lifx/message.rb
CHANGED
data/lib/lifx/network_context.rb
CHANGED
@@ -151,6 +151,11 @@ module LIFX
|
|
151
151
|
transport_manager.gateways.map(&:values).flatten
|
152
152
|
end
|
153
153
|
|
154
|
+
def to_s
|
155
|
+
%Q{#<LIFX::NetworkContext connections=#{gateway_connections}>}
|
156
|
+
end
|
157
|
+
alias_method :inspect, :to_s
|
158
|
+
|
154
159
|
protected
|
155
160
|
|
156
161
|
def handle_message(message, ip, transport)
|
data/lib/lifx/observable.rb
CHANGED
data/lib/lifx/protocol/device.rb
CHANGED
data/lib/lifx/protocol/light.rb
CHANGED
data/lib/lifx/protocol/sensor.rb
CHANGED
data/lib/lifx/protocol/wan.rb
CHANGED
data/lib/lifx/protocol/wifi.rb
CHANGED
data/lib/lifx/protocol_path.rb
CHANGED
data/lib/lifx/routing_manager.rb
CHANGED
data/lib/lifx/routing_table.rb
CHANGED
data/lib/lifx/seen.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
module LIFX
|
2
2
|
module Seen
|
3
|
+
# Returns the time when the device was last seen.
|
4
|
+
# @return [Time]
|
3
5
|
def last_seen
|
4
6
|
@last_seen
|
5
7
|
end
|
6
8
|
|
9
|
+
# Returns the number of seconds since the device was last seen.
|
10
|
+
# If the device hasn't been seen yet, it will use Unix epoch as
|
11
|
+
# the time it was seen.
|
12
|
+
# @return [Float]
|
7
13
|
def seconds_since_seen
|
8
14
|
Time.now - (last_seen || Time.at(0))
|
9
15
|
end
|
10
16
|
|
17
|
+
# Marks the device as being seen.
|
18
|
+
# @private
|
11
19
|
def seen!
|
12
20
|
@last_seen = Time.now
|
13
21
|
end
|
data/lib/lifx/tag_manager.rb
CHANGED
data/lib/lifx/target.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module LIFX
|
2
|
+
# Target is a high-level abstraction for the target of a Message
|
2
3
|
# @api private
|
3
|
-
|
4
4
|
class Target
|
5
|
-
# Target is a high-level abstraction for the target of a Message
|
6
5
|
|
7
6
|
attr_reader :site_id, :device_id, :tag, :broadcast
|
8
7
|
def initialize(device_id: nil, site_id: nil, tag: nil, broadcast: nil)
|
data/lib/lifx/timers.rb
CHANGED
data/lib/lifx/transport/tcp.rb
CHANGED
data/lib/lifx/transport/udp.rb
CHANGED
data/lib/lifx/utilities.rb
CHANGED
data/lib/lifx/version.rb
CHANGED
@@ -4,15 +4,15 @@ module LIFX
|
|
4
4
|
describe Client, integration: true do
|
5
5
|
describe '#sync' do
|
6
6
|
it 'schedules sending all messages to be executed at the same time' do
|
7
|
+
if lights.count < 3
|
8
|
+
pending "This test requires 3 or more lights tagged under Test"
|
9
|
+
return
|
10
|
+
end
|
7
11
|
|
8
12
|
lifx.discover! do
|
9
13
|
lights.count >= 3
|
10
14
|
end
|
11
15
|
|
12
|
-
if lights.count < 3
|
13
|
-
fail "This test requires 3 or more lights tagged under Test"
|
14
|
-
end
|
15
|
-
|
16
16
|
white = LIFX::Color.white(brightness: 0.5)
|
17
17
|
lights.set_color(white, duration: 0)
|
18
18
|
sleep 1
|
@@ -37,4 +37,4 @@ module LIFX
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lifx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|