lifx 0.4.3 → 0.4.4
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/CHANGES.md +7 -0
- data/README.md +1 -0
- data/lib/lifx/transport/udp.rb +1 -1
- data/lib/lifx/version.rb +1 -1
- data/spec/color_spec.rb +13 -32
- data/spec/gateway_connection_spec.rb +12 -16
- data/spec/integration/client_spec.rb +10 -10
- data/spec/integration/light_spec.rb +14 -14
- data/spec/integration/tags_spec.rb +12 -10
- data/spec/light_collection_spec.rb +37 -0
- data/spec/message_spec.rb +69 -51
- data/spec/protocol_path_spec.rb +27 -29
- data/spec/routing_manager_spec.rb +9 -8
- data/spec/spec_helper.rb +1 -4
- data/spec/transport/udp_spec.rb +17 -15
- data/spec/transport_spec.rb +3 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5454b2eb54cd767b3967cf5a6846ec306522599
|
4
|
+
data.tar.gz: 43f84ba663f3beece220825ca095d59417f6ab78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 918213bcae91fd85b24f90b5db998b46e9064dbcecf8ac6929bfcd9a697c5511c8ca0efac5e87570274db43491a0b499584fa45fdf15e8b712b0b5a2272622ef
|
7
|
+
data.tar.gz: a198a724a716d6444cdca5ba117d633ddc94c030dff4b3d31f49166740ec5009e6dda07dcda9760dcd5a5083426c48fee60515daaf582d90e9b6188aee112e71
|
data/CHANGES.md
ADDED
data/README.md
CHANGED
data/lib/lifx/transport/udp.rb
CHANGED
@@ -33,7 +33,7 @@ module LIFX
|
|
33
33
|
@listener = Thread.new do
|
34
34
|
reader = UDPSocket.new
|
35
35
|
reader.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
|
36
|
-
reader.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true)
|
36
|
+
reader.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true) if Socket.const_defined?('SO_REUSEPORT')
|
37
37
|
reader.bind(ip, port)
|
38
38
|
loop do
|
39
39
|
begin
|
data/lib/lifx/version.rb
CHANGED
data/spec/color_spec.rb
CHANGED
@@ -3,42 +3,23 @@ require 'spec_helper'
|
|
3
3
|
module LIFX
|
4
4
|
describe Color do
|
5
5
|
let(:default_kelvin) { 3500 }
|
6
|
+
|
6
7
|
describe '.rgb' do
|
7
8
|
context 'translating from RGB' do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
it 'translates yellow correctly' do
|
14
|
-
c = Color.rgb(255, 255, 0)
|
15
|
-
c.to_a.should == [60, 1, 1, default_kelvin]
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'translates green correctly' do
|
19
|
-
c = Color.rgb(0, 255, 0)
|
20
|
-
c.to_a.should == [120, 1, 1, default_kelvin]
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'translates cyan correctly' do
|
24
|
-
c = Color.rgb(0, 255, 255)
|
25
|
-
c.to_a.should == [180, 1, 1, default_kelvin]
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'translates blue correctly' do
|
29
|
-
c = Color.rgb(0, 0, 255)
|
30
|
-
c.to_a.should == [240, 1, 1, default_kelvin]
|
9
|
+
shared_examples 'translating color' do |name, rgb, expected|
|
10
|
+
it "translates #{name} correctly" do
|
11
|
+
translation = Color.rgb(*rgb).to_a
|
12
|
+
expect(translation).to eq [*expected, default_kelvin]
|
13
|
+
end
|
31
14
|
end
|
32
15
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
c.to_a.should == [0, 0, 0, default_kelvin]
|
41
|
-
end
|
16
|
+
it_behaves_like 'translating color', 'red', [255, 0, 0], [0, 1, 1]
|
17
|
+
it_behaves_like 'translating color', 'yellow', [255, 255, 0], [60, 1, 1]
|
18
|
+
it_behaves_like 'translating color', 'green', [0, 255, 0], [120, 1, 1]
|
19
|
+
it_behaves_like 'translating color', 'cyan', [0, 255, 255], [180, 1, 1]
|
20
|
+
it_behaves_like 'translating color', 'blue', [0, 0, 255], [240, 1, 1]
|
21
|
+
it_behaves_like 'translating color', 'white', [255, 255, 255], [0, 0, 1]
|
22
|
+
it_behaves_like 'translating color', 'black', [0, 0, 0], [0, 0, 0]
|
42
23
|
end
|
43
24
|
end
|
44
25
|
end
|
@@ -2,30 +2,26 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module LIFX
|
4
4
|
describe GatewayConnection do
|
5
|
-
subject
|
6
|
-
GatewayConnection.new
|
7
|
-
end
|
5
|
+
subject(:gateway) { GatewayConnection.new }
|
8
6
|
|
9
|
-
let(:message) { double(Message
|
7
|
+
let(:message) { double(Message, is_a?: true, pack: '') }
|
10
8
|
let(:ip) { '127.0.0.1' }
|
11
|
-
let(:port) {
|
9
|
+
let(:port) { 35_003 }
|
12
10
|
|
13
|
-
after
|
14
|
-
subject.close
|
15
|
-
end
|
11
|
+
after { gateway.close }
|
16
12
|
|
17
13
|
context 'write queue resiliency' do
|
18
14
|
it 'does not send if there is no available connection' do
|
19
|
-
expect(
|
20
|
-
|
21
|
-
expect {
|
15
|
+
expect(gateway).to_not receive(:actually_write)
|
16
|
+
gateway.write(message)
|
17
|
+
expect { gateway.flush(timeout: 0.5) }.to raise_error(Timeout::Error)
|
22
18
|
end
|
23
|
-
|
19
|
+
|
24
20
|
it 'pushes message back into queue if unable to write' do
|
25
|
-
|
26
|
-
expect(
|
27
|
-
|
28
|
-
|
21
|
+
gateway.connect_udp(ip, port)
|
22
|
+
expect(gateway).to receive(:actually_write).and_return(false, true)
|
23
|
+
gateway.write(message)
|
24
|
+
gateway.flush
|
29
25
|
end
|
30
26
|
end
|
31
27
|
end
|
@@ -3,35 +3,35 @@ require 'spec_helper'
|
|
3
3
|
module LIFX
|
4
4
|
describe Client, integration: true do
|
5
5
|
describe '#sync' do
|
6
|
+
let(:minimum_lights) { 3 }
|
7
|
+
let(:udp) { Transport::UDP.new('0.0.0.0', 56_750) }
|
8
|
+
let(:white) { Color.white(brightness: 0.5) }
|
9
|
+
|
6
10
|
it 'schedules sending all messages to be executed at the same time' do
|
7
|
-
if lights.count <
|
8
|
-
pending
|
11
|
+
if lights.count < minimum_lights
|
12
|
+
pending 'This test requires 3 or more lights tagged under Test'
|
9
13
|
return
|
10
14
|
end
|
11
15
|
|
12
|
-
lifx.discover!
|
13
|
-
lights.count >= 3
|
14
|
-
end
|
16
|
+
lifx.discover! { lights.count >= minimum_lights }
|
15
17
|
|
16
|
-
white = LIFX::Color.white(brightness: 0.5)
|
17
18
|
lights.set_color(white, duration: 0)
|
18
19
|
sleep 1
|
19
20
|
|
20
|
-
udp = Transport::UDP.new('0.0.0.0', 56750)
|
21
21
|
msgs = []
|
22
22
|
udp.add_observer(self) do |message:, ip:, transport:|
|
23
23
|
msgs << message if message.payload.is_a?(Protocol::Light::SetWaveform)
|
24
24
|
end
|
25
25
|
udp.listen
|
26
26
|
|
27
|
-
|
27
|
+
lifx.sync do
|
28
28
|
lights.each do |light|
|
29
29
|
light.pulse(LIFX::Color.hsb(rand(360), 1, 1), period: 1)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
msgs.count.
|
34
|
-
msgs.map(&:at_time).uniq.count.
|
33
|
+
expect(msgs.count).to eq lights.count
|
34
|
+
expect(msgs.map(&:at_time).uniq.count).to eq 1
|
35
35
|
|
36
36
|
flush
|
37
37
|
end
|
@@ -3,41 +3,41 @@ require 'spec_helper'
|
|
3
3
|
module LIFX
|
4
4
|
describe Light, integration: true do
|
5
5
|
describe '#set_power' do
|
6
|
-
it
|
6
|
+
it 'sets the power of the light asynchronously' do
|
7
7
|
light.set_power(0)
|
8
|
-
wait { light.
|
8
|
+
wait { expect(light).to be_off }
|
9
9
|
light.set_power(1)
|
10
|
-
wait { light.
|
10
|
+
wait { expect(light).to be_on }
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#set_power!' do
|
15
|
-
it
|
15
|
+
it 'sets the power of the light synchronously' do
|
16
16
|
light.set_power!(0)
|
17
|
-
light.
|
17
|
+
expect(light).to be_off
|
18
18
|
light.set_power!(1)
|
19
|
-
light.
|
19
|
+
expect(light).to be_on
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe '#set_color' do
|
24
|
-
|
25
|
-
|
24
|
+
let(:color) { Color.hsb(rand(360), rand, rand) }
|
25
|
+
|
26
|
+
it 'sets the color of the light asynchronously' do
|
26
27
|
light.set_color(color, duration: 0)
|
27
28
|
sleep 1
|
28
29
|
light.refresh
|
29
|
-
wait { light.color.
|
30
|
+
wait { expect(light.color).to eq color }
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
describe '#set_label' do
|
34
|
-
|
35
|
-
|
35
|
+
let(:label) { light.label.sub(/\d+|$/, rand(100).to_s) }
|
36
|
+
|
37
|
+
it 'sets the label of the light synchronously' do
|
36
38
|
light.set_label(label)
|
37
|
-
light.label.
|
39
|
+
expect(light.label).to eq label
|
38
40
|
end
|
39
41
|
end
|
40
|
-
|
41
|
-
|
42
42
|
end
|
43
43
|
end
|
@@ -1,31 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module LIFX
|
4
|
-
describe
|
5
|
-
|
4
|
+
describe 'tags', integration: true do
|
5
|
+
let(:color) { Color.hsb(rand(360), 0.3, 0.3) }
|
6
|
+
|
7
|
+
specify 'Clearing, setting and using tags' do
|
6
8
|
light.add_tag('Foo')
|
7
|
-
light.tags.
|
9
|
+
expect(light.tags).to include('Foo')
|
8
10
|
|
9
11
|
test_tag = lights.with_tag('Foo')
|
10
12
|
test_tag.turn_on
|
11
|
-
|
12
|
-
test_tag.set_color(color, duration: 0)
|
13
|
+
test_tag.set_color(color, duration: 0)
|
13
14
|
flush
|
14
15
|
sleep 1 # Set messages are scheduled 250ms if no at_time is set
|
15
|
-
# It also returns the current light state rather than the
|
16
|
+
# It also returns the current light state rather than the
|
17
|
+
# final state
|
16
18
|
light.refresh
|
17
|
-
wait { light.color.
|
19
|
+
wait { expect(light.color).to eq color }
|
18
20
|
|
19
21
|
light.remove_tag('Foo')
|
20
|
-
wait { light.tags.
|
22
|
+
wait { expect(light.tags).not_to include('Foo') }
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'deletes tags when no longer assigned to a light' do
|
24
26
|
light.add_tag('TempTag')
|
25
27
|
light.remove_tag('TempTag')
|
26
|
-
lifx.unused_tags.
|
28
|
+
expect(lifx.unused_tags).to include('TempTag')
|
27
29
|
lifx.purge_unused_tags!
|
28
|
-
lifx.unused_tags.
|
30
|
+
expect(lifx.unused_tags).to be_empty
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module LIFX
|
4
|
+
describe LightCollection do
|
5
|
+
subject(:collection) { LightCollection.new(context: double) }
|
6
|
+
|
7
|
+
describe '#with_id' do
|
8
|
+
it 'returns a Light with matching id' do
|
9
|
+
light = double(Light, id: 'id')
|
10
|
+
collection.stub(lights: [light])
|
11
|
+
expect(collection.with_id('id')).to eq light
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns nil when none matches' do
|
15
|
+
light = double(Light, id: 'id')
|
16
|
+
collection.stub(lights: [light])
|
17
|
+
ret = collection.with_id('wrong id')
|
18
|
+
expect(ret).to eq nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#with_label' do
|
23
|
+
it 'returns a Light with matching label' do
|
24
|
+
light = double(Light, label: 'label')
|
25
|
+
collection.stub(lights: [light])
|
26
|
+
expect(collection.with_label('label')).to eq light
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns nil' do
|
30
|
+
light = double(Light, label: 'label')
|
31
|
+
collection.stub(lights: [light])
|
32
|
+
ret = collection.with_label('wrong label')
|
33
|
+
expect(ret).to eq nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/message_spec.rb
CHANGED
@@ -2,53 +2,58 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe LIFX::Message do
|
4
4
|
context 'unpacking' do
|
5
|
-
let(:data)
|
5
|
+
let(:data) do
|
6
|
+
"\x39\x00\x00\x34\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x31" \
|
7
|
+
"\x6c\x69\x66\x78\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x67\x00" \
|
8
|
+
"\x00\x00\x00\x01\x00\x00\xff\xff\xff\xff\xac\x0d\xc8\x00\x00\x00\x00" \
|
9
|
+
"\x00\x80\x3f\x00\x00\x00".b
|
10
|
+
end
|
6
11
|
let(:msg) { LIFX::Message.unpack(data) }
|
7
12
|
|
8
13
|
it 'unpacks without errors' do
|
9
|
-
msg.
|
14
|
+
expect(msg).not_to be_nil
|
10
15
|
end
|
11
16
|
|
12
17
|
it 'returns the correct frame data' do
|
13
|
-
msg.msg_size.
|
14
|
-
msg.protocol.
|
15
|
-
msg.
|
18
|
+
expect(msg.msg_size).to eq 57
|
19
|
+
expect(msg.protocol).to eq 1024
|
20
|
+
expect(msg).to be_addressable
|
16
21
|
end
|
17
22
|
|
18
23
|
it 'returns the correct address data' do
|
19
|
-
msg.raw_site.
|
20
|
-
msg.raw_target.
|
24
|
+
expect(msg.raw_site).to eq '1lifx1'
|
25
|
+
expect(msg.raw_target).to eq "\x00" * 8
|
21
26
|
end
|
22
27
|
|
23
28
|
it 'has correct ProtocolPath data' do
|
24
|
-
msg.path.
|
25
|
-
msg.path.site_id.
|
26
|
-
msg.path.tag_ids.
|
27
|
-
msg.path.device_id.
|
29
|
+
expect(msg.path).to be_a(LIFX::ProtocolPath)
|
30
|
+
expect(msg.path.site_id).to eq '316c69667831'
|
31
|
+
expect(msg.path.tag_ids).to eq []
|
32
|
+
expect(msg.path.device_id).to be_nil
|
28
33
|
end
|
29
34
|
|
30
35
|
it 'returns the correct metadata' do
|
31
|
-
msg.at_time.
|
32
|
-
msg.type.
|
36
|
+
expect(msg.at_time).to eq 0
|
37
|
+
expect(msg.type).to eq 103
|
33
38
|
end
|
34
39
|
|
35
40
|
let(:payload) { msg.payload }
|
36
41
|
it 'returns the payload' do
|
37
|
-
payload.class.
|
38
|
-
payload.stream.
|
39
|
-
payload.transient.
|
40
|
-
payload.color.hue.
|
41
|
-
payload.color.saturation.
|
42
|
-
payload.color.brightness.
|
43
|
-
payload.color.kelvin.
|
44
|
-
payload.period.
|
45
|
-
payload.cycles.
|
46
|
-
payload.duty_cycle.
|
47
|
-
payload.waveform.
|
42
|
+
expect(payload.class).to eq LIFX::Protocol::Light::SetWaveform
|
43
|
+
expect(payload.stream).to eq 0
|
44
|
+
expect(payload.transient).to be_true
|
45
|
+
expect(payload.color.hue).to eq 0
|
46
|
+
expect(payload.color.saturation).to eq 65_535
|
47
|
+
expect(payload.color.brightness).to eq 65_535
|
48
|
+
expect(payload.color.kelvin).to eq 3_500
|
49
|
+
expect(payload.period).to eq 200
|
50
|
+
expect(payload.cycles).to eq 1.0
|
51
|
+
expect(payload.duty_cycle).to eq 0
|
52
|
+
expect(payload.waveform).to eq 0
|
48
53
|
end
|
49
54
|
|
50
55
|
it 'repacks to the same data' do
|
51
|
-
msg.pack.
|
56
|
+
expect(msg.pack).to eq data
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
@@ -72,42 +77,50 @@ describe LIFX::Message do
|
|
72
77
|
context 'passed in via hash' do
|
73
78
|
let(:msg) do
|
74
79
|
LIFX::Message.new({
|
75
|
-
path: LIFX::ProtocolPath.new(tagged: false, raw_target:
|
80
|
+
path: LIFX::ProtocolPath.new(tagged: false, raw_target: 'abcdefgh'),
|
76
81
|
at_time: 9001,
|
77
82
|
payload: LIFX::Protocol::Wifi::SetAccessPoint.new(
|
78
83
|
interface: 1,
|
79
|
-
ssid:
|
80
|
-
pass:
|
84
|
+
ssid: 'who let the dogs out',
|
85
|
+
pass: 'woof, woof, woof woof!',
|
81
86
|
security: 1
|
82
87
|
)
|
83
88
|
})
|
84
89
|
end
|
90
|
+
# let(:unpacked) { LIFX::Message.unpack(msg.pack) }
|
85
91
|
|
86
92
|
it 'sets the size' do
|
87
|
-
msg.msg_size.
|
93
|
+
expect(msg.msg_size).to eq 134
|
88
94
|
end
|
89
95
|
|
90
96
|
it 'packs correctly' do
|
91
|
-
msg.pack.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
msg.
|
101
|
-
msg.
|
102
|
-
msg.
|
103
|
-
msg.
|
97
|
+
expect(msg.pack).to eq "\x86\x00\x00\x14\x00\x00\x00\x00abcdefgh\x00" \
|
98
|
+
"\x00\x00\x00\x00\x00\x00\x00)#\x00\x00\x00" \
|
99
|
+
"\x00\x00\x001\x01\x00\x00\x01who let the " \
|
100
|
+
"dogs out\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
|
101
|
+
"\x00\x00\x00woof, woof, woof woof!\x00\x00" \
|
102
|
+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
|
103
|
+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
|
104
|
+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
|
105
|
+
"\x00\x00\x00\x00\x00\x00\x00\x01".b
|
106
|
+
expect(msg.protocol).to eq 1024
|
107
|
+
expect(msg.path).not_to be_tagged
|
108
|
+
expect(msg).to be_addressable
|
109
|
+
expect(msg.path.raw_target).to eq 'abcdefgh'
|
110
|
+
expect(msg.at_time).to eq 9001
|
111
|
+
expect(msg.type).to eq 305
|
112
|
+
expect(msg.payload.class).to eq LIFX::Protocol::Wifi::SetAccessPoint
|
113
|
+
expect(msg.payload.interface).to eq 1
|
114
|
+
expect(msg.payload.ssid).to eq 'who let the dogs out'
|
115
|
+
expect(msg.payload.pass).to eq 'woof, woof, woof woof!'
|
116
|
+
expect(msg.payload.security).to eq 1
|
104
117
|
end
|
105
118
|
end
|
106
119
|
|
107
120
|
context 'packing with tags' do
|
108
121
|
let(:msg) do
|
109
122
|
LIFX::Message.new({
|
110
|
-
path: LIFX::ProtocolPath.new(tag_ids: [0,1]),
|
123
|
+
path: LIFX::ProtocolPath.new(tag_ids: [0, 1]),
|
111
124
|
at_time: 9001,
|
112
125
|
payload: LIFX::Protocol::Device::GetTime.new
|
113
126
|
})
|
@@ -116,19 +129,22 @@ describe LIFX::Message do
|
|
116
129
|
let(:unpacked) { LIFX::Message.unpack(msg.pack) }
|
117
130
|
|
118
131
|
it 'packs the tag correctly' do
|
119
|
-
msg.pack.
|
132
|
+
expect(msg.pack).to eq "$\x00\x004\x00\x00\x00\x00\x03\x00\x00\x00" \
|
133
|
+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
|
134
|
+
"\x00)#\x00\x00\x00\x00\x00\x00\x04\x00\x00" \
|
135
|
+
"\x00".b
|
120
136
|
end
|
121
137
|
|
122
138
|
it 'sets tagged' do
|
123
|
-
unpacked.path.
|
139
|
+
expect(unpacked.path).to be_tagged
|
124
140
|
end
|
125
141
|
|
126
142
|
it 'sets tags' do
|
127
|
-
unpacked.path.tag_ids.
|
143
|
+
expect(unpacked.path.tag_ids).to eq [0, 1]
|
128
144
|
end
|
129
145
|
|
130
146
|
it 'device should be nil' do
|
131
|
-
unpacked.path.device_id.
|
147
|
+
expect(unpacked.path.device_id).to be_nil
|
132
148
|
end
|
133
149
|
end
|
134
150
|
|
@@ -144,19 +160,21 @@ describe LIFX::Message do
|
|
144
160
|
let(:unpacked) { LIFX::Message.unpack(msg.pack) }
|
145
161
|
|
146
162
|
it 'packs the tag correctly' do
|
147
|
-
msg.pack.
|
163
|
+
expect(msg.pack).to eq "$\x00\x00\x14\x00\x00\x00\x00\x01#Eg\x89\xAB" \
|
164
|
+
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00)#" \
|
165
|
+
"\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00".b
|
148
166
|
end
|
149
167
|
|
150
168
|
it 'sets tagged to false' do
|
151
|
-
unpacked.path.
|
169
|
+
expect(unpacked.path).not_to be_tagged
|
152
170
|
end
|
153
171
|
|
154
172
|
it 'sets device' do
|
155
|
-
unpacked.path.device_id.
|
173
|
+
expect(unpacked.path.device_id).to eq '0123456789ab'
|
156
174
|
end
|
157
175
|
|
158
176
|
it 'tags should be nil' do
|
159
|
-
unpacked.path.tag_ids.
|
177
|
+
expect(unpacked.path.tag_ids).to be_nil
|
160
178
|
end
|
161
179
|
end
|
162
180
|
end
|
data/spec/protocol_path_spec.rb
CHANGED
@@ -3,47 +3,49 @@ require 'spec_helper'
|
|
3
3
|
module LIFX
|
4
4
|
describe ProtocolPath do
|
5
5
|
describe 'initializing from raw data' do
|
6
|
+
subject do
|
7
|
+
ProtocolPath.new(raw_site: '1lifx1', raw_target: target, tagged: tagged)
|
8
|
+
end
|
9
|
+
|
6
10
|
context 'device target' do
|
7
|
-
|
8
|
-
|
9
|
-
end
|
11
|
+
let(:target) { "\xAB\xCD\xEF\x12\x34\x56\x00\x00" }
|
12
|
+
let(:tagged) { false }
|
10
13
|
|
11
14
|
it 'returns site_id in hex' do
|
12
|
-
subject.site_id.
|
15
|
+
expect(subject.site_id).to eq '316c69667831'
|
13
16
|
end
|
14
17
|
|
15
18
|
it 'returns device_id in hex' do
|
16
|
-
subject.device_id.
|
19
|
+
expect(subject.device_id).to eq 'abcdef123456'
|
17
20
|
end
|
18
21
|
|
19
22
|
it 'returns tagged as false' do
|
20
|
-
subject.
|
23
|
+
expect(subject).not_to be_tagged
|
21
24
|
end
|
22
25
|
|
23
26
|
it 'returns nil for tag_ids' do
|
24
|
-
subject.tag_ids.
|
27
|
+
expect(subject.tag_ids).to be_nil
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
31
|
context 'tagged target' do
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
+
let(:target) { "\x03\x00\x00\x00\x00\x00\x00\x00" }
|
33
|
+
let(:tagged) { true }
|
32
34
|
|
33
35
|
it 'returns site_id in hex' do
|
34
|
-
subject.site_id.
|
36
|
+
expect(subject.site_id).to eq '316c69667831'
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'returns device_id as nil' do
|
38
|
-
subject.device_id.
|
40
|
+
expect(subject.device_id).to be_nil
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'returns tagged as true' do
|
42
|
-
subject.
|
44
|
+
expect(subject).to be_tagged
|
43
45
|
end
|
44
46
|
|
45
47
|
it 'returns the tag_ids' do
|
46
|
-
subject.tag_ids.
|
48
|
+
expect(subject.tag_ids).to eq [0, 1]
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -51,11 +53,11 @@ module LIFX
|
|
51
53
|
describe 'initializing from strings' do
|
52
54
|
context 'device target' do
|
53
55
|
subject do
|
54
|
-
ProtocolPath.new(site_id:
|
56
|
+
ProtocolPath.new(site_id: '316c69667831', device_id: 'abcdef123456')
|
55
57
|
end
|
56
58
|
|
57
59
|
it 'sets raw_site correctly' do
|
58
|
-
subject.raw_site.
|
60
|
+
expect(subject.raw_site).to eq '1lifx1'
|
59
61
|
end
|
60
62
|
|
61
63
|
it 'sets raw_target correctly' do
|
@@ -69,41 +71,37 @@ module LIFX
|
|
69
71
|
|
70
72
|
context 'tagged target' do
|
71
73
|
subject do
|
72
|
-
ProtocolPath.new(site_id:
|
74
|
+
ProtocolPath.new(site_id: '316c69667831', tag_ids: [0, 1])
|
73
75
|
end
|
74
76
|
|
75
77
|
it 'sets raw_site properly' do
|
76
|
-
subject.raw_site.
|
78
|
+
expect(subject.raw_site).to eq '1lifx1'
|
77
79
|
end
|
78
80
|
|
79
81
|
it 'sets raw_target correctly' do
|
80
|
-
subject.raw_target.
|
82
|
+
expect(subject.raw_target).to eq "\x03\x00\x00\x00\x00\x00\x00\x00".b
|
81
83
|
end
|
82
84
|
|
83
85
|
it 'returns tagged as true' do
|
84
|
-
subject.
|
86
|
+
expect(subject).to be_tagged
|
85
87
|
end
|
86
88
|
end
|
87
89
|
|
88
90
|
context 'tagged target with no site' do
|
89
|
-
subject
|
90
|
-
ProtocolPath.new(tagged: true)
|
91
|
-
end
|
91
|
+
subject { ProtocolPath.new(tagged: true) }
|
92
92
|
|
93
93
|
it 'raw_site should be null string' do
|
94
|
-
subject.raw_site.
|
94
|
+
expect(subject.raw_site).to eq "\x00\x00\x00\x00\x00\x00".b
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'sets raw_target correctly' do
|
98
|
-
subject.raw_target.
|
98
|
+
expect(subject.raw_target).to eq "\x00\x00\x00\x00\x00\x00\x00\x00".b
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'returns tagged as true' do
|
102
|
-
subject.
|
102
|
+
expect(subject).to be_tagged
|
103
103
|
end
|
104
104
|
end
|
105
|
-
|
106
105
|
end
|
107
|
-
|
108
106
|
end
|
109
|
-
end
|
107
|
+
end
|
@@ -3,19 +3,20 @@ require 'spec_helper'
|
|
3
3
|
module LIFX
|
4
4
|
describe RoutingManager do
|
5
5
|
describe '#tags_for_device_id' do
|
6
|
-
subject
|
7
|
-
RoutingManager.new(context: double)
|
8
|
-
end
|
6
|
+
subject(:manager) { RoutingManager.new(context: double) }
|
9
7
|
|
10
8
|
before do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
['Some label', 'Another label', 'Much label'].each_with_index do |lbl, i|
|
10
|
+
manager.tag_table.update_table(site_id: 'site', tag_id: i, label: lbl)
|
11
|
+
end
|
12
|
+
|
13
|
+
manager.routing_table
|
14
|
+
.update_table(site_id: 'site', device_id: 'device', tag_ids: [0, 2])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'resolves tags' do
|
18
|
-
|
18
|
+
tags = manager.tags_for_device_id('device')
|
19
|
+
expect(tags).to eq ['Some label', 'Much label']
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -41,12 +41,9 @@ shared_context 'integration', integration: true do
|
|
41
41
|
let(:light) { lights.first }
|
42
42
|
end
|
43
43
|
|
44
|
-
if ENV['DEBUG']
|
45
|
-
LIFX::Config.logger = Yell.new(STDERR)
|
46
|
-
end
|
44
|
+
LIFX::Config.logger = Yell.new(STDERR) if ENV['DEBUG']
|
47
45
|
|
48
46
|
RSpec.configure do |config|
|
49
47
|
config.formatter = 'documentation'
|
50
48
|
config.color = true
|
51
49
|
end
|
52
|
-
|
data/spec/transport/udp_spec.rb
CHANGED
@@ -1,38 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe LIFX::Transport::UDP do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
subject(:udp) { LIFX::Transport::UDP.new(host, port) }
|
5
|
+
|
6
|
+
let(:host) { 'localhost' }
|
7
|
+
let(:message) { double }
|
8
|
+
let(:port) { 45_828 }
|
8
9
|
|
9
10
|
describe '#write' do
|
10
|
-
let(:message) { double }
|
11
11
|
let(:payload) { double }
|
12
|
+
|
12
13
|
it 'writes a Message to specified host' do
|
13
|
-
message.
|
14
|
-
UDPSocket.
|
15
|
-
|
14
|
+
expect(message).to receive(:pack).and_return(payload)
|
15
|
+
expect_any_instance_of(UDPSocket).to receive(:send)
|
16
|
+
.with(payload, 0, host, port)
|
17
|
+
udp.write(message)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
describe '#listen' do
|
20
22
|
let(:raw_message) { 'some binary data' }
|
21
|
-
let(:message) { double }
|
22
23
|
let(:socket) { UDPSocket.new }
|
23
24
|
|
24
25
|
it 'listens to the specified socket data, unpacks it and notifies observers' do
|
25
26
|
messages = []
|
26
|
-
|
27
|
+
udp.add_observer(self) do |message:, ip:, transport:|
|
27
28
|
messages << message
|
28
29
|
end
|
29
|
-
|
30
|
+
udp.listen
|
30
31
|
|
31
|
-
LIFX::Message.
|
32
|
-
|
32
|
+
expect(LIFX::Message).to receive(:unpack)
|
33
|
+
.with(raw_message)
|
34
|
+
.and_return(message)
|
35
|
+
socket.send(raw_message, 0, host, port)
|
33
36
|
sleep 0.01
|
34
|
-
messages.
|
37
|
+
expect(messages).to include(message)
|
35
38
|
end
|
36
|
-
|
37
39
|
end
|
38
40
|
end
|
data/spec/transport_spec.rb
CHANGED
@@ -6,9 +6,9 @@ describe LIFX::Transport do
|
|
6
6
|
|
7
7
|
describe 'initialize' do
|
8
8
|
it 'takes an host and port' do
|
9
|
-
transport = LIFX::Transport.new('127.0.0.1',
|
10
|
-
transport.host.
|
11
|
-
transport.port.
|
9
|
+
transport = LIFX::Transport.new('127.0.0.1', 31_337)
|
10
|
+
expect(transport.host).to eq '127.0.0.1'
|
11
|
+
expect(transport.port).to eq 31_337
|
12
12
|
end
|
13
13
|
end
|
14
14
|
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.4
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -118,6 +118,7 @@ extra_rdoc_files: []
|
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
120
|
- ".yardopts"
|
121
|
+
- CHANGES.md
|
121
122
|
- Gemfile
|
122
123
|
- LICENSE.txt
|
123
124
|
- README.md
|
@@ -177,6 +178,7 @@ files:
|
|
177
178
|
- spec/integration/client_spec.rb
|
178
179
|
- spec/integration/light_spec.rb
|
179
180
|
- spec/integration/tags_spec.rb
|
181
|
+
- spec/light_collection_spec.rb
|
180
182
|
- spec/message_spec.rb
|
181
183
|
- spec/protocol_path_spec.rb
|
182
184
|
- spec/routing_manager_spec.rb
|
@@ -215,6 +217,7 @@ test_files:
|
|
215
217
|
- spec/integration/client_spec.rb
|
216
218
|
- spec/integration/light_spec.rb
|
217
219
|
- spec/integration/tags_spec.rb
|
220
|
+
- spec/light_collection_spec.rb
|
218
221
|
- spec/message_spec.rb
|
219
222
|
- spec/protocol_path_spec.rb
|
220
223
|
- spec/routing_manager_spec.rb
|