lifx 0.4.10 → 0.4.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lifx/config.rb +2 -0
- data/lib/lifx/light.rb +9 -8
- data/lib/lifx/light_collection.rb +5 -4
- data/lib/lifx/light_target.rb +6 -12
- data/lib/lifx/network_context.rb +3 -2
- data/lib/lifx/protocol/light.rb +1 -1
- data/lib/lifx/routing_manager.rb +1 -0
- data/lib/lifx/tag_manager.rb +1 -1
- data/lib/lifx/version.rb +1 -1
- data/spec/integration/light_spec.rb +13 -2
- data/spec/integration/tags_spec.rb +7 -0
- data/spec/message_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0570f28dd8c1392dd1f3d1602d128ac3c3595184
|
4
|
+
data.tar.gz: 3e58c32ab27c29eac2c5dd794d3ce778ddf77c9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d001b9118b4d9648758ff41ffa12bad61e37c1df1fe3068ed9bdc47a65d0ba094856562c7781937379a7e8bcd6a13264c813faf99ac5e1c4501f6194470dcc6
|
7
|
+
data.tar.gz: 46d2a75c7c97f304c8fd3f8394e70f5d58d1c80ac50ce0f7958f035158da012c00f87b410cdbe613066cfa2e6a21fa7c07180cbe8015103ad759223045951517
|
data/lib/lifx/config.rb
CHANGED
@@ -4,6 +4,8 @@ module LIFX
|
|
4
4
|
Config = Configatron::Store.new
|
5
5
|
|
6
6
|
Config.default_duration = 1
|
7
|
+
Config.message_wait_timeout = 3
|
8
|
+
Config.message_retry_interval = 0.5
|
7
9
|
Config.broadcast_ip = '255.255.255.255'
|
8
10
|
Config.allowed_transports = [:udp, :tcp]
|
9
11
|
Config.log_invalid_messages = false
|
data/lib/lifx/light.rb
CHANGED
@@ -98,11 +98,11 @@ module LIFX
|
|
98
98
|
# @raise [LabelTooLong] if label is greater than {MAX_LABEL_LENGTH}
|
99
99
|
# @return [Light] self
|
100
100
|
def set_label(label)
|
101
|
-
if label.length > MAX_LABEL_LENGTH
|
102
|
-
raise LabelTooLong.new("Label length must be below or equal to #{MAX_LABEL_LENGTH}")
|
101
|
+
if label.bytes.length > MAX_LABEL_LENGTH
|
102
|
+
raise LabelTooLong.new("Label length in bytes must be below or equal to #{MAX_LABEL_LENGTH}")
|
103
103
|
end
|
104
104
|
while self.label != label
|
105
|
-
send_message!(Protocol::Device::SetLabel.new(label: label), wait_for: Protocol::Device::StateLabel)
|
105
|
+
send_message!(Protocol::Device::SetLabel.new(label: label.encode('utf-8')), wait_for: Protocol::Device::StateLabel)
|
106
106
|
end
|
107
107
|
self
|
108
108
|
end
|
@@ -356,9 +356,10 @@ module LIFX
|
|
356
356
|
# Queues a message to be sent the Light
|
357
357
|
# @param payload [Protocol::Payload] the payload to send
|
358
358
|
# @param acknowledge: [Boolean] whether the device should respond
|
359
|
+
# @param at_time: [Integer] Unix epoch in milliseconds to run the payload. Only applicable to certain payload types.
|
359
360
|
# @return [Light] returns self for chaining
|
360
|
-
def send_message(payload, acknowledge: true)
|
361
|
-
context.send_message(target: Target.new(device_id: id, site_id: @site_id), payload: payload, acknowledge: acknowledge)
|
361
|
+
def send_message(payload, acknowledge: true, at_time: nil)
|
362
|
+
context.send_message(target: Target.new(device_id: id, site_id: @site_id), payload: payload, acknowledge: acknowledge, at_time: at_time)
|
362
363
|
end
|
363
364
|
|
364
365
|
# An exception for when synchronous messages take too long to receive a response
|
@@ -373,7 +374,7 @@ module LIFX
|
|
373
374
|
# @param block: [Proc] the block that is executed when the expected `wait_for` payload comes back. If the return value is false or nil, it will try to send the message again.
|
374
375
|
# @return [Object] the truthy result of `block` is returned.
|
375
376
|
# @raise [MessageTimeout] if the device doesn't respond in time
|
376
|
-
def send_message!(payload, wait_for: wait_for, wait_timeout:
|
377
|
+
def send_message!(payload, wait_for: wait_for, wait_timeout: Config.message_wait_timeout, retry_interval: Config.message_retry_interval, &block)
|
377
378
|
if Thread.current[:sync_enabled]
|
378
379
|
raise "Cannot use synchronous methods inside a sync block"
|
379
380
|
end
|
@@ -385,7 +386,7 @@ module LIFX
|
|
385
386
|
result = block.call(payload)
|
386
387
|
}
|
387
388
|
add_hook(wait_for, proc)
|
388
|
-
try_until -> { result }, signal: @message_signal do
|
389
|
+
try_until -> { result }, action_interval: retry_interval, signal: @message_signal do
|
389
390
|
send_message(payload)
|
390
391
|
end
|
391
392
|
result
|
@@ -405,7 +406,7 @@ module LIFX
|
|
405
406
|
|
406
407
|
def add_hooks
|
407
408
|
add_hook(Protocol::Device::StateLabel) do |payload|
|
408
|
-
@label = payload.label.to_s
|
409
|
+
@label = payload.label.to_s.force_encoding('utf-8')
|
409
410
|
seen!
|
410
411
|
end
|
411
412
|
|
@@ -22,7 +22,7 @@ module LIFX
|
|
22
22
|
# Creates a {LightCollection} instance. Should not be used directly.
|
23
23
|
# @api private
|
24
24
|
# @param context: [NetworkContext] NetworkContext this collection belongs to
|
25
|
-
# @param tag: [String] Tag
|
25
|
+
# @param tag: [String] Tag
|
26
26
|
def initialize(context: required!(:context), tag: nil)
|
27
27
|
@context = context
|
28
28
|
@tag = tag
|
@@ -31,13 +31,14 @@ module LIFX
|
|
31
31
|
# Queues a {Protocol::Payload} to be sent to bulbs in the collection
|
32
32
|
# @param payload [Protocol::Payload] Payload to be sent
|
33
33
|
# @param acknowledge: [Boolean] whether recipients should acknowledge message
|
34
|
+
# @param at_time: [Integer] Unix epoch in milliseconds to run the payload. Only applicable to certain payload types.
|
34
35
|
# @api private
|
35
36
|
# @return [LightCollection] self for chaining
|
36
|
-
def send_message(payload, acknowledge: false)
|
37
|
+
def send_message(payload, acknowledge: false, at_time: nil)
|
37
38
|
if tag
|
38
|
-
context.send_message(target: Target.new(tag: tag), payload: payload, acknowledge: acknowledge)
|
39
|
+
context.send_message(target: Target.new(tag: tag), payload: payload, acknowledge: acknowledge, at_time: at_time)
|
39
40
|
else
|
40
|
-
context.send_message(target: Target.new(broadcast: true), payload: payload, acknowledge: acknowledge)
|
41
|
+
context.send_message(target: Target.new(broadcast: true), payload: payload, acknowledge: acknowledge, at_time: at_time)
|
41
42
|
end
|
42
43
|
self
|
43
44
|
end
|
data/lib/lifx/light_target.rb
CHANGED
@@ -26,7 +26,7 @@ module LIFX
|
|
26
26
|
stream: 0,
|
27
27
|
transient: true,
|
28
28
|
period: 1.0,
|
29
|
-
|
29
|
+
skew_ratio: 0.5,
|
30
30
|
acknowledge: false)
|
31
31
|
send_message(Protocol::Light::SetWaveform.new(
|
32
32
|
color: color.to_hsbk,
|
@@ -35,7 +35,7 @@ module LIFX
|
|
35
35
|
stream: stream,
|
36
36
|
transient: transient,
|
37
37
|
period: (period * 1_000).to_i,
|
38
|
-
|
38
|
+
skew_ratio: (skew_ratio * 65535).round - 32768,
|
39
39
|
), acknowledge: acknowledge)
|
40
40
|
end
|
41
41
|
|
@@ -55,7 +55,7 @@ module LIFX
|
|
55
55
|
stream: 0)
|
56
56
|
set_waveform(color, waveform: Protocol::Light::Waveform::PULSE,
|
57
57
|
cycles: cycles,
|
58
|
-
|
58
|
+
skew_ratio: 1 - duty_cycle,
|
59
59
|
stream: stream,
|
60
60
|
transient: transient,
|
61
61
|
period: period)
|
@@ -77,7 +77,7 @@ module LIFX
|
|
77
77
|
stream: 0)
|
78
78
|
set_waveform(color, waveform: Protocol::Light::Waveform::SINE,
|
79
79
|
cycles: cycles,
|
80
|
-
|
80
|
+
skew_ratio: peak,
|
81
81
|
stream: stream,
|
82
82
|
transient: transient,
|
83
83
|
period: period)
|
@@ -112,10 +112,12 @@ module LIFX
|
|
112
112
|
# @note Marked as private pending bug fixes in firmware
|
113
113
|
def triangle(color, cycles: 1,
|
114
114
|
period: 1.0,
|
115
|
+
peak: 0.5,
|
115
116
|
transient: true,
|
116
117
|
stream: 0)
|
117
118
|
set_waveform(color, waveform: Protocol::Light::Waveform::TRIANGLE,
|
118
119
|
cycles: cycles,
|
120
|
+
skew_ratio: peak,
|
119
121
|
stream: stream,
|
120
122
|
transient: transient,
|
121
123
|
period: period)
|
@@ -197,13 +199,5 @@ module LIFX
|
|
197
199
|
def set_time(time = Time.now)
|
198
200
|
send_message(Protocol::Device::SetTime.new(time: (time.to_f * NSEC_IN_SEC).round))
|
199
201
|
end
|
200
|
-
|
201
|
-
|
202
|
-
# Attempts to reboots the light(s).
|
203
|
-
# This method cannot guarantee the message was received.
|
204
|
-
# @return [Light, LightCollection] self for chaining
|
205
|
-
def reboot!
|
206
|
-
send_message(Protocol::Device::Reboot.new)
|
207
|
-
end
|
208
202
|
end
|
209
203
|
end
|
data/lib/lifx/network_context.rb
CHANGED
@@ -61,11 +61,12 @@ module LIFX
|
|
61
61
|
# @param target: [Target] Target of the message
|
62
62
|
# @param payload: [Protocol::Payload] Message payload
|
63
63
|
# @param acknowledge: [Boolean] If recipients must acknowledge with a response
|
64
|
-
|
64
|
+
# @param at_time: [Integer] Unix epoch in milliseconds to run the payload. Only applicable to certain payload types.
|
65
|
+
def send_message(target: required!(:target), payload: required!(:payload), acknowledge: false, at_time: nil)
|
65
66
|
paths = @routing_manager.resolve_target(target)
|
66
67
|
|
67
68
|
messages = paths.map do |path|
|
68
|
-
Message.new(path: path, payload: payload, acknowledge: acknowledge)
|
69
|
+
Message.new(path: path, payload: payload, acknowledge: acknowledge, at_time: at_time)
|
69
70
|
end
|
70
71
|
|
71
72
|
if within_sync?
|
data/lib/lifx/protocol/light.rb
CHANGED
data/lib/lifx/routing_manager.rb
CHANGED
data/lib/lifx/tag_manager.rb
CHANGED
@@ -28,7 +28,7 @@ module LIFX
|
|
28
28
|
# we don't receive a StateTagLabels before another tag gets created
|
29
29
|
@tag_table.update_table(tag_id: id, label: label, site_id: site_id)
|
30
30
|
context.send_message(target: Target.new(site_id: site_id),
|
31
|
-
payload: Protocol::Device::SetTagLabels.new(tags: id_to_tags_field(id), label: label))
|
31
|
+
payload: Protocol::Device::SetTagLabels.new(tags: id_to_tags_field(id), label: label.encode('utf-8')))
|
32
32
|
end
|
33
33
|
|
34
34
|
def add_tag_to_device(tag: required!(:tag), device: required!(:device))
|
data/lib/lifx/version.rb
CHANGED
@@ -32,11 +32,22 @@ module LIFX
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe '#set_label' do
|
35
|
-
let(:
|
35
|
+
let!(:original_label) { light.label }
|
36
|
+
|
37
|
+
after do
|
38
|
+
light.set_label(original_label)
|
39
|
+
end
|
36
40
|
|
37
41
|
it 'sets the label of the light synchronously' do
|
42
|
+
label = light.label.sub(/\d+|$/, rand(100).to_s)
|
43
|
+
light.set_label(label)
|
44
|
+
expect(light.label).to eq(label)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'works with accented characters' do
|
48
|
+
label = 'tést'
|
38
49
|
light.set_label(label)
|
39
|
-
expect(light.label).to eq
|
50
|
+
expect(light.label).to eq(label)
|
40
51
|
end
|
41
52
|
end
|
42
53
|
end
|
@@ -29,5 +29,12 @@ module LIFX
|
|
29
29
|
lifx.purge_unused_tags!
|
30
30
|
expect(lifx.unused_tags).to be_empty
|
31
31
|
end
|
32
|
+
|
33
|
+
it 'handles non-ascii tags' do
|
34
|
+
light.add_tag('_tést')
|
35
|
+
expect(light.tags).to include('_tést')
|
36
|
+
light.remove_tag('_tést')
|
37
|
+
lifx.purge_unused_tags!
|
38
|
+
end
|
32
39
|
end
|
33
40
|
end
|
data/spec/message_spec.rb
CHANGED
@@ -48,7 +48,7 @@ describe LIFX::Message do
|
|
48
48
|
expect(payload.color.kelvin).to eq 3_500
|
49
49
|
expect(payload.period).to eq 200
|
50
50
|
expect(payload.cycles).to eq 1.0
|
51
|
-
expect(payload.
|
51
|
+
expect(payload.skew_ratio).to eq 0
|
52
52
|
expect(payload.waveform).to eq 0
|
53
53
|
end
|
54
54
|
|
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.11
|
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-
|
11
|
+
date: 2014-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -215,3 +215,4 @@ test_files:
|
|
215
215
|
- spec/spec_helper.rb
|
216
216
|
- spec/transport/udp_spec.rb
|
217
217
|
- spec/transport_spec.rb
|
218
|
+
has_rdoc:
|