somfy_sdn 1.0.10 → 1.0.11

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
2
  SHA256:
3
- metadata.gz: 57ade06be997d5f36fa76aa13c87aa00e26b1bfe07de7a7fd29b9015f249a1a3
4
- data.tar.gz: '03462586cabf999666ac43e83036811b8a10df15515ea17d7bfd7b4d2e421e3a'
3
+ metadata.gz: ef81905b4b164a5e09d771e07b286f09df6d40cd259b8253c2a0ef1f01f649e4
4
+ data.tar.gz: 4d6f3ad72d6b2e8f06c530a8657d684f4f0b12c9d54eb13e998841b18a8e37dd
5
5
  SHA512:
6
- metadata.gz: '00080b23f47bd5c11c13406d818feec587c744b132cb1b1f4cbd57f3a64cd002c0747e4bccb575315e996b7ec7b92d736a5892116c31b277f85fcbf83fd36c6f'
7
- data.tar.gz: '01700481ff1ed2966a00287c5c9f1193b600b56518ce36da8a06dae4768daa51fac0da4635993b9eb3daf6ea8a0f068f3e8fd7aee5bd9977e3350eb46aa58d6a'
6
+ metadata.gz: 8bf05e27c1e7c50e6893198950d7ab91099807c9d8ad139629e89fe3fc97d6f46c87e93400e1083ecba7c64ec3638a302523804fd921125414aa62f3632e5edb
7
+ data.tar.gz: 3300c346eeb666d82c686c0e5dec4fb830fa96adabdd7dbc45f3d4cd8e609c13f2796d1ae0b6cd2b2186bcf1ae3251d180e17dd33d578ccfa29eba3f86870e4a
@@ -5,6 +5,14 @@ module SDN
5
5
 
6
6
  class Message
7
7
  class << self
8
+ def expected_response
9
+ if name =~ /::Get([A-Za-z]+)/
10
+ const_get("Post#{$1}", true)
11
+ else
12
+ Ack
13
+ end
14
+ end
15
+
8
16
  def parse(data)
9
17
  offset = -1
10
18
  msg = length = ack_requested = message_class = nil
@@ -79,7 +79,8 @@ module SDN
79
79
  :ip15percent,
80
80
  :ip16pulses,
81
81
  :ip16percent,
82
- :groups) do
82
+ :groups,
83
+ :last_action) do
83
84
  def initialize(*)
84
85
  members.each { |k| self[k] = :nil }
85
86
  @groups = [].fill(nil, 0, 16)
@@ -158,12 +159,13 @@ module SDN
158
159
  'baud' => 4800,
159
160
  'parity' => Net::Telnet::RFC2217::ODD)
160
161
  else
161
- require 'serialport'
162
- @sdn = SerialPort.open(port, "baud" => 4800, "parity" => SerialPort::ODD)
162
+ require 'ccutrer-serialport'
163
+ @sdn = CCutrer::SerialPort.new(port, baud: 4800, parity: :odd)
163
164
  end
164
165
 
165
166
  read_thread = Thread.new do
166
167
  buffer = ""
168
+
167
169
  loop do
168
170
  begin
169
171
  message, bytes_read = SDN::Message.parse(buffer.bytes)
@@ -173,7 +175,7 @@ module SDN
173
175
  begin
174
176
  buffer.concat(@sdn.read_nonblock(64 * 1024))
175
177
  next
176
- rescue IO::WaitReadable
178
+ rescue IO::WaitReadable, EOFError
177
179
  wait = buffer.empty? ? nil : WAIT_TIME
178
180
  if @sdn.wait_readable(wait).nil?
179
181
  # timed out; just discard everything
@@ -214,7 +216,12 @@ module SDN
214
216
  group.publish(:positionpercent, position)
215
217
  end
216
218
  when SDN::Message::PostMotorStatus
217
- if message.state == :running || motor.state == :running
219
+ if message.state == :running || motor.state == :running ||
220
+ # if it's explicitly stopped, but we didn't ask it to, it's probably
221
+ # changing directions so keep querying
222
+ (message.state == :stopped &&
223
+ message.last_action_cause == :explicit_command &&
224
+ !(motor.last_action == SDN::Message::Stop || motor.last_action.nil?))
218
225
  follow_ups << SDN::Message::GetMotorStatus.new(message.src)
219
226
  end
220
227
  # this will do one more position request after it stopped
@@ -245,8 +252,11 @@ module SDN
245
252
  end
246
253
 
247
254
  @mutex.synchronize do
248
- signal = @response_pending || !follow_ups.empty?
249
- @response_pending = @broadcast_pending
255
+ correct_response = @response_pending && message.src == @prior_message&.message&.dest && message.is_a?(@prior_message&.message&.class&.expected_response)
256
+ signal = correct_response || !follow_ups.empty?
257
+ puts "correct response #{correct_response}"
258
+ puts "pending: #{@response_pending} #{@broadcast_pending}"
259
+ @response_pending = @broadcast_pending if correct_response
250
260
  follow_ups.each do |follow_up|
251
261
  @queues[1].push(MessageAndRetries.new(follow_up, 5, 1)) unless @queues[1].any? { |mr| mr.message == follow_up }
252
262
  end
@@ -321,7 +331,7 @@ module SDN
321
331
  puts "(and waiting for response)" if @response_pending
322
332
  serialized = message.serialize
323
333
  @sdn.write(serialized)
324
- @sdn.flush
334
+ @sdn.flush if @sdn.respond_to?(:flush)
325
335
  puts "wrote #{serialized.unpack("C*").map { |b| '%02x' % b }.join(' ')}"
326
336
  end
327
337
  rescue => e
@@ -421,6 +431,11 @@ module SDN
421
431
  end
422
432
  nil
423
433
  end
434
+
435
+ if motor
436
+ motor.last_action = message.class if [Message::MoveTo, Message::Move, Message::Wink, Message::Stop].include?(message.class)
437
+ end
438
+
424
439
  if message
425
440
  message.ack_requested = true if message.class.name !~ /^SDN::Message::Get/
426
441
  @mutex.synchronize do
@@ -1,3 +1,3 @@
1
1
  module SDN
2
- VERSION = '1.0.10'
2
+ VERSION = '1.0.11'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: somfy_sdn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-31 00:00:00.000000000 Z
11
+ date: 2020-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mqtt
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.3
41
41
  - !ruby/object:Gem::Dependency
42
- name: serialport
42
+ name: ccutrer-serialport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.3.1
47
+ version: 1.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.3.1
54
+ version: 1.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: byebug
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '13.0'
83
- description:
83
+ description:
84
84
  email: cody@cutrer.com'
85
85
  executables:
86
86
  - sdn_mqtt_bridge
@@ -105,7 +105,7 @@ homepage: https://github.com/ccutrer/somfy_sdn
105
105
  licenses:
106
106
  - MIT
107
107
  metadata: {}
108
- post_install_message:
108
+ post_install_message:
109
109
  rdoc_options: []
110
110
  require_paths:
111
111
  - lib
@@ -120,8 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.0.3
124
- signing_key:
123
+ rubygems_version: 3.1.2
124
+ signing_key:
125
125
  specification_version: 4
126
126
  summary: Library for communication with Somfy SDN RS-485 motorized shades
127
127
  test_files: []