lifx-lan 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4ef94c0b7aaaa1efaf0ed5510237c2f8e8638c69
4
- data.tar.gz: 24ecd96f704325934c37882f5bd7f7417dbb4287
2
+ SHA256:
3
+ metadata.gz: fc244c5415dfac35bff4c8c80184c4940d89cfec2c5fb6dbf047d710f942283a
4
+ data.tar.gz: b775bf867f79b919fafd741ebe2adaed14700f3f99bb8d876644cb7b2fc19f66
5
5
  SHA512:
6
- metadata.gz: 87d2775a26c2104f0789d07a9bb38ea1dda76ca5d03ac3031bdd41190f76cabc34e932a5785edc940e67458fdab064874a10d50f6a06a0d41da159d8f596157a
7
- data.tar.gz: 18691da3eb56988e02c2a3fb94ec9f74b1271a901ea80b76a80e6c91e85bad86b32ea7c5c77051687df06495a88e406810a8fbea5dfa6f48bd6ca53d20c1bc36
6
+ metadata.gz: d71cc69208fbf7f8750814903751e5069c9c8a27103aebc6615b48129a350d91674efe675ce8e01f25218744b5cc8c18f8574b194dee29c686641bf017b4cbbe
7
+ data.tar.gz: a34bd68e7efdd872f5b82876f73b62f51d220d3bf0fa65b7749d4c2bd4627778c5a986c69e951e0c9bfcc49e1511328546ad2e437b20b2be1e03c911d4801147
@@ -334,6 +334,26 @@ module LIFX
334
334
  context.tags_for_device(self)
335
335
  end
336
336
 
337
+ def location
338
+ send_message!(Protocol::Device::GetLocation.new,
339
+ wait_for: Protocol::Device::StateLocation) do |payload|
340
+ {
341
+ location: payload.location,
342
+ label: payload.label
343
+ }
344
+ end
345
+ end
346
+
347
+ def group
348
+ send_message!(Protocol::Device::GetGroup.new,
349
+ wait_for: Protocol::Device::StateGroup) do |payload|
350
+ {
351
+ group: payload.group,
352
+ label: payload.label
353
+ }
354
+ end
355
+ end
356
+
337
357
  # Returns whether the light is a gateway
338
358
  # @api private
339
359
  def gateway?
@@ -10,7 +10,7 @@ module LIFX
10
10
  # @param color [Color] The color to be set
11
11
  # @param duration: [Numeric] Transition time in seconds
12
12
  # @return [Light, LightCollection] self for chaining
13
- def set_color(color, duration: LIFX::Config.default_duration)
13
+ def set_color(color, duration: LIFX::LAN::Config.default_duration)
14
14
  send_message(Protocol::Light::SetColor.new(
15
15
  color: color.to_hsbk,
16
16
  duration: (duration * MSEC_PER_SEC).to_i,
@@ -19,6 +19,60 @@ module LIFX
19
19
  self
20
20
  end
21
21
 
22
+ # Attempts to set multiple zones on the light(s) to `color` asynchronously.
23
+ # This method cannot guarantee that the message was received.
24
+ # @param color [Color] The color to be set
25
+ # @param start_index [Numeric] The index of the first zone to be set
26
+ # @param end_index [Numeric] The index of the last zone to be set
27
+ # @param duration: [Numeric] Transition time in seconds
28
+ # @return [Light, LightCollection] self for chaining
29
+ def set_multizone_color(color, start_index: 0, end_index: 7, duration: LIFX::LAN::Config.default_duration)
30
+ send_message(Protocol::MultiZone::SetColorZones.new(
31
+ start_index: start_index,
32
+ end_index: end_index,
33
+ color: color.to_hsbk,
34
+ duration: (duration * MSEC_PER_SEC).to_i,
35
+ apply: 1,
36
+ ))
37
+ self
38
+ end
39
+
40
+ # Attempts to set every pixel on the tile(s) to `colors` asynchronously.
41
+ # This method cannot guarantee that the message was received.
42
+ # @param colors [Array<Color>] The 64 Colors to be set as a 1-d array
43
+ # @param tile_start_index [Numeric] The index of the first tile to be set
44
+ # @param length [Numeric] The number of tiles to set starting from the index
45
+ # @param duration: [Numeric] Transition time in seconds
46
+ # @return [Light, LightCollection] self for chaining
47
+ def set_tile_colors(colors, tile_start_index: 0, length: 1, duration: LIFX::LAN::Config.default_duration)
48
+ send_message(Protocol::Tile::SetTileState64.new(
49
+ colors: colors.map(&:to_hsbk),
50
+ tile_start_index: tile_start_index,
51
+ tile_length: [length, 1].min,
52
+ x: 0,
53
+ y: 0,
54
+ width: 8,
55
+ duration: (duration * MSEC_PER_SEC).to_i
56
+ ))
57
+ self
58
+ end
59
+
60
+ # @return [Numeric] Number of zones supported
61
+ def zone_count
62
+ send_message!(Protocol::MultiZone::GetColorZones.new(start_index: 0, end_index: 0),
63
+ wait_for: Protocol::MultiZone::StateZone) do |payload|
64
+ payload.total_zones
65
+ end
66
+ end
67
+
68
+ # @return [Hash] Raw tile info
69
+ def tile_info
70
+ send_message!(Protocol::Tile::GetDeviceChain.new,
71
+ wait_for: Protocol::Tile::StateDeviceChain) do |payload|
72
+ payload
73
+ end
74
+ end
75
+
22
76
  # Attempts to apply a waveform to the light(s) asynchronously.
23
77
  # @note Don't use this directly.
24
78
  # @api private
@@ -0,0 +1,90 @@
1
+ require "lifx/lan/protocol/light"
2
+
3
+ module LIFX
4
+ module LAN
5
+ module Protocol
6
+ # @api private
7
+ module MultiZone
8
+ module ApplicationRequest
9
+ NO_APPLY = 0 # Don't apply the requested changes until a message with APPLY or APPLY_ONLY is sent.
10
+ APPLY = 1 # Apply the changes immediately and apply any pending changes.
11
+ APPLY_ONLY = 2 # Ignore the requested changes in this message and only apply pending changes.
12
+ end
13
+
14
+ # #####
15
+ # Extended Multizone requests: Unsupported by LIFX Z gen 1
16
+ # #####
17
+
18
+ # Change all the zones on your device in one message
19
+ class SetExtendedColorZones < Payload
20
+ endian :little
21
+
22
+ uint32 :duration # Transition duration in milliseconds
23
+ uint8 :apply # ApplicationRequest
24
+ uint16 :start_index # Zone we start applying the colors from. The first zone is 0.
25
+ uint8 :colors_count # Number of colors from colors will be applied sequentially from index
26
+ array :colors, :initial_length => 82 do
27
+ hsbk
28
+ end
29
+ end
30
+
31
+ # Ask the device to return a StateExtendedColorZones
32
+ class GetExtendedColorZones < Payload
33
+ endian :little
34
+ end
35
+
36
+ # StateExtendedColorZones
37
+ class StateExtendedColorZones < Payload
38
+ endian :little
39
+
40
+ uint16 :total_zones
41
+ uint16 :start_index
42
+ uint8 :colors_count
43
+ array :colors, :initial_length => 82 do
44
+ hsbk
45
+ end
46
+ end
47
+
48
+
49
+ # #####
50
+ # All LIFX Z and LIFX Beam products supported:
51
+ # #####
52
+
53
+ class SetColorZones < Payload
54
+ endian :little
55
+
56
+ uint8 :start_index
57
+ uint8 :end_index
58
+ hsbk :color
59
+ uint32 :duration # Transition duration in milliseconds
60
+ uint8 :apply # ApplicationRequest
61
+ end
62
+
63
+ class GetColorZones < Payload
64
+ endian :little
65
+
66
+ uint8 :start_index
67
+ uint8 :end_index
68
+ end
69
+
70
+ class StateZone < Payload
71
+ endian :little
72
+
73
+ uint8 :total_zones
74
+ uint8 :color_index
75
+ hsbk :color
76
+ end
77
+
78
+ class StateMultiZone < Payload
79
+ endian :little
80
+
81
+ uint8 :total_zones
82
+ uint8 :start_index
83
+ array :colors, :initial_length => 8 do
84
+ hsbk
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,96 @@
1
+ require "lifx/lan/protocol/light"
2
+
3
+ module LIFX
4
+ module LAN
5
+ module Protocol
6
+ # @api private
7
+ module Tile
8
+ class Tile < Payload
9
+ endian :little
10
+
11
+ # 55 bytes
12
+ int16 :accel_meas_x # Gravity measurements for determining orientation
13
+ int16 :accel_meas_y # Gravity measurements for determining orientation
14
+ int16 :accel_meas_z # Gravity measurements for determining orientation
15
+ int16 :reserved_0 #
16
+ float :user_x # Position of the tile relative to the chain
17
+ float :user_y # Position of the tile relative to the chain
18
+ uint8 :width # Number of pixels that are on each axis of the tile
19
+ uint8 :height # Number of pixels that are on each axis of the tile
20
+ uint8 :reserved_1 #
21
+ uint32 :device_version_vendor # Same as in Device::StateVersion
22
+ uint32 :device_version_product # Same as in Device::StateVersion
23
+ uint32 :device_version_version # Same as in Device::StateVersion
24
+ uint64 :firmware_build # Same as in Device::StateHostFirmware
25
+ uint64 :reserved_2 #
26
+ uint16 :firmware_version_minor # Same as in Device::StateHostFirmware
27
+ uint16 :firmware_version_major # Same as in Device::StateHostFirmware
28
+ uint32 :reserved_3 #
29
+ end
30
+
31
+ class GetDeviceChain < Payload
32
+ endian :little
33
+ end
34
+
35
+ class StateDeviceChain < Payload
36
+ endian :little
37
+
38
+ uint8 :start_index
39
+ array :tile_devices, :initial_length => 5 do
40
+ tile
41
+ end
42
+ uint8 :total_count
43
+ end
44
+
45
+ # Read this before using: https://lan.developer.lifx.com/v2.0/docs/tile-control
46
+ class SetUserPosition < Payload
47
+ endian :little
48
+
49
+ uint8 :tile_index
50
+ uint16 :reserved
51
+ float :user_x
52
+ float :user_y
53
+ end
54
+
55
+ class GetTileState64 < Payload
56
+ endian :little
57
+
58
+ uint8 :tile_start_index
59
+ uint8 :tile_length
60
+ uint8 :reserved
61
+ uint8 :x
62
+ uint8 :y
63
+ uint8 :width
64
+ end
65
+
66
+ class StateTileState64 < Payload
67
+ endian :little
68
+
69
+ uint8 :tile_index
70
+ uint8 :reserved
71
+ uint8 :x
72
+ uint8 :y
73
+ uint8 :width
74
+ array :colors, :initial_length => 64 do
75
+ hsbk
76
+ end
77
+ end
78
+
79
+ class SetTileState64 < Payload
80
+ endian :little
81
+
82
+ uint8 :tile_start_index
83
+ uint8 :tile_length
84
+ uint8 :reserved
85
+ uint8 :x
86
+ uint8 :y
87
+ uint8 :width
88
+ uint32 :duration
89
+ array :colors, :initial_length => 64 do
90
+ hsbk
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -99,106 +99,24 @@ module LIFX
99
99
  402 => Sensor::StateAmbientLight,
100
100
  403 => Sensor::GetDimmerVoltage,
101
101
  404 => Sensor::StateDimmerVoltage,
102
- }
103
102
 
104
- CLASS_TO_TYPE_ID = {
105
- # Device::SetSite => 1,
106
- # Device::GetPanGateway => 2,
107
- # Device::StatePanGateway => 3,
108
- Device::GetService => 2,
109
- Device::StateService => 3,
110
- Device::GetTime => 4,
111
- Device::SetTime => 5,
112
- Device::StateTime => 6,
113
- # Device::GetResetSwitch => 7,
114
- # Device::StateResetSwitch => 8,
115
- # Device::GetMeshInfo => 12,
116
- # Device::StateMeshInfo => 13,
117
- # Device::GetMeshFirmware => 14,
118
- # Device::StateMeshFirmware => 15,
119
- Device::GetHostInfo => 12,
120
- Device::StateHostInfo => 13,
121
- Device::GetHostFirmware => 14,
122
- Device::StateHostFirmware => 15,
123
- Device::GetWifiInfo => 16,
124
- Device::StateWifiInfo => 17,
125
- Device::GetWifiFirmware => 18,
126
- Device::StateWifiFirmware => 19,
127
- Device::GetPower => 20,
128
- Device::SetPower => 21,
129
- Device::StatePower => 22,
130
- Device::GetLabel => 23,
131
- Device::SetLabel => 24,
132
- Device::StateLabel => 25,
133
- Device::GetTags => 26,
134
- Device::SetTags => 27,
135
- Device::StateTags => 28,
136
- Device::GetTagLabels => 29,
137
- Device::SetTagLabels => 30,
138
- Device::StateTagLabels => 31,
139
- Device::GetVersion => 32,
140
- Device::StateVersion => 33,
141
- Device::GetInfo => 34,
142
- Device::StateInfo => 35,
143
- # Device::GetMcuRailVoltage => 36,
144
- # Device::StateMcuRailVoltage => 37,
145
- # Device::Reboot => 38,
146
- Device::SetReboot => 38,
147
- Device::StateReboot => 43,
148
- Device::Acknowledgement => 45,
149
- Device::SetFactoryReset => 46,
150
- Device::StateFactoryReset => 47,
151
- Device::GetLocation => 48,
152
- Device::SetLocation => 49,
153
- Device::StateLocation => 50,
154
- Device::GetGroup => 51,
155
- Device::SetGroup => 52,
156
- Device::StateGroup => 53,
157
- Device::GetOwner => 54,
158
- Device::SetOwner => 55,
159
- Device::StateOwner => 56,
160
- Device::EchoRequest => 58,
161
- Device::EchoResponse => 59,
103
+ 510 => MultiZone::SetExtendedColorZones,
104
+ 511 => MultiZone::GetExtendedColorZones,
105
+ 512 => MultiZone::StateExtendedColorZones,
106
+ 501 => MultiZone::SetColorZones,
107
+ 502 => MultiZone::GetColorZones,
108
+ 503 => MultiZone::StateZone,
109
+ 506 => MultiZone::StateMultiZone,
162
110
 
163
- Light::Get => 101,
164
- # Light::Set => 102,
165
- Light::SetColor => 102,
166
- # Light::SetWaveform => 103,
167
- # Light::SetDimAbsolute => 104,
168
- # Light::SetDimRelative => 105,
169
- # Light::SetRgbw => 106,
170
- Light::State => 107,
171
- # Light::GetRailVoltage => 108,
172
- # Light::StateRailVoltage => 109,
173
- Light::GetTemperature => 110,
174
- Light::StateTemperature => 111,
175
- Light::GetPower => 116,
176
- Light::SetPower => 117,
177
- Light::StatePower => 118,
111
+ 701 => Tile::GetDeviceChain,
112
+ 702 => Tile::StateDeviceChain,
113
+ 703 => Tile::SetUserPosition,
114
+ 707 => Tile::GetTileState64,
115
+ 711 => Tile::StateTileState64,
116
+ 715 => Tile::SetTileState64,
117
+ }.freeze
178
118
 
179
- Wan::ConnectPlain => 201,
180
- Wan::ConnectKey => 202,
181
- Wan::StateConnect => 203,
182
- Wan::Sub => 204,
183
- Wan::Unsub => 205,
184
- Wan::StateSub => 206,
185
-
186
- Wifi::Get => 301,
187
- Wifi::Set => 302,
188
- Wifi::State => 303,
189
- # Wifi::GetAccessPoint => 304,
190
- Wifi::GetAccessPoints => 304,
191
- Wifi::SetAccessPoint => 305,
192
- # Wifi::StateAccessPoint => 306,
193
- Wifi::StateAccessPoints => 306,
194
- Wifi::GetAccessPoint => 307,
195
- Wifi::StateAccessPoint => 308,
196
-
197
- Sensor::GetAmbientLight => 401,
198
- Sensor::StateAmbientLight => 402,
199
- Sensor::GetDimmerVoltage => 403,
200
- Sensor::StateDimmerVoltage => 404,
201
- }
119
+ CLASS_TO_TYPE_ID = TYPE_ID_TO_CLASS.invert.freeze
202
120
  end
203
121
  end
204
122
  end
@@ -50,7 +50,7 @@ module LIFX
50
50
  reader.bind(ip, port)
51
51
  loop do
52
52
  begin
53
- bytes, (_, _, ip, _) = reader.recvfrom(128)
53
+ bytes, (_, _, ip, _) = reader.recvfrom(1280)
54
54
  logger.debug("<- #{bytes.each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join}")
55
55
  message = Message.unpack(bytes)
56
56
  logger.debug("<- Incoming message: #{message}")
@@ -1,5 +1,5 @@
1
1
  module LIFX
2
2
  module LAN
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/lifx-lan.rb CHANGED
@@ -10,7 +10,7 @@ require "lifx/lan/logging"
10
10
  require "lifx/lan/thread"
11
11
 
12
12
  require "lifx/lan/protocol/payload"
13
- %w(device light sensor wan wifi message).each { |f| require "lifx/lan/protocol/#{f}" }
13
+ %w(device light sensor wan wifi message multi_zone tile).each { |f| require "lifx/lan/protocol/#{f}" }
14
14
  require "lifx/lan/protocol/type"
15
15
  require "lifx/lan/message"
16
16
  require "lifx/lan/transport"
data/lifx-lan.gemspec CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "bindata", "~> 2.0"
23
23
  spec.add_dependency "timers", "~> 1.0"
24
24
  spec.add_dependency "configatron", "~> 3.0"
25
- spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "bundler", "~> 2"
26
26
  end
data/spec/spec_helper.rb CHANGED
@@ -16,7 +16,7 @@ shared_context 'integration', integration: true do
16
16
  c.discover! do
17
17
  c.tags.include?('_Test') && c.lights.with_tag('_Test').count > 0
18
18
  end
19
- rescue LIFX::Client::DiscoveryTimeout
19
+ rescue LIFX::LAN::Client::DiscoveryTimeout
20
20
  raise "Could not find any lights with tag _Test in #{c.lights.inspect}"
21
21
  end
22
22
  c
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifx-lan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Chen (chendo), Julian Cheal (juliancheal)
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.3'
61
+ version: '2'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.3'
68
+ version: '2'
69
69
  description: A Ruby gem that allows easy interaction with LIFX devices.
70
70
  email:
71
71
  - julian.cheal+lifx-gem@lifx.co
@@ -108,8 +108,10 @@ files:
108
108
  - lib/lifx/lan/protocol/light.rb
109
109
  - lib/lifx/lan/protocol/message.rb
110
110
  - lib/lifx/lan/protocol/metadata.rb
111
+ - lib/lifx/lan/protocol/multi_zone.rb
111
112
  - lib/lifx/lan/protocol/payload.rb
112
113
  - lib/lifx/lan/protocol/sensor.rb
114
+ - lib/lifx/lan/protocol/tile.rb
113
115
  - lib/lifx/lan/protocol/type.rb
114
116
  - lib/lifx/lan/protocol/wan.rb
115
117
  - lib/lifx/lan/protocol/wifi.rb
@@ -149,7 +151,7 @@ homepage: https://github.com/juliancheal/lifx-lan
149
151
  licenses:
150
152
  - MIT
151
153
  metadata: {}
152
- post_install_message:
154
+ post_install_message:
153
155
  rdoc_options: []
154
156
  require_paths:
155
157
  - lib
@@ -164,9 +166,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
166
  - !ruby/object:Gem::Version
165
167
  version: '0'
166
168
  requirements: []
167
- rubyforge_project:
168
- rubygems_version: 2.6.13
169
- signing_key:
169
+ rubygems_version: 3.3.3
170
+ signing_key:
170
171
  specification_version: 4
171
172
  summary: A Ruby gem that allows easy interaction with LIFX devices. Handles discovery,
172
173
  rate limiting, tags, gateway connections and provides an object-based API for interacting