homie-mqtt 1.4.0 → 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mqtt/homie/device.rb +8 -4
- data/lib/mqtt/homie/node.rb +2 -2
- data/lib/mqtt/homie/property.rb +4 -2
- data/lib/mqtt/homie/version.rb +1 -1
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c95ecceb8af9d97949e7ee75cccf878f80270ff703c07ee957b9b276c96f6538
|
4
|
+
data.tar.gz: 0162763dce328e5c4a43045740ca5e907d0506de4e8fc05592c524763274e965
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53500d60691a22a98a46c81e0f5c6627bcc356503186f5275b4c643321254719ac6effbb094241f1f37800859f80f6ec4b9b5c2749e91f4169ec38e1073d9595
|
7
|
+
data.tar.gz: 4ee3a6ba42de0f71746c1211e4d9e543d3587d7f7d79524667e71b40a61e3a65a5a23ec90a8e09dc318399528b65345d863df423b3a5f5cd44cd3378e2cbcb9f
|
data/lib/mqtt/homie/device.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'mqtt'
|
4
|
+
require 'ruby2_keywords'
|
4
5
|
|
5
6
|
module MQTT
|
6
7
|
module Homie
|
7
8
|
class Device < Base
|
8
9
|
attr_reader :root_topic, :state, :mqtt
|
10
|
+
attr_accessor :logger
|
11
|
+
attr_accessor :out_of_band_topic_proc
|
9
12
|
|
10
13
|
def initialize(id, name, root_topic: nil, mqtt: nil, clear_topics: true, &block)
|
11
14
|
super(id, name)
|
@@ -13,7 +16,7 @@ module MQTT
|
|
13
16
|
@state = :init
|
14
17
|
@nodes = {}
|
15
18
|
@published = false
|
16
|
-
@
|
19
|
+
@out_of_band_topic_proc = block
|
17
20
|
mqtt = MQTT::Client.new(mqtt) if mqtt.is_a?(String)
|
18
21
|
@mqtt = mqtt || MQTT::Client.new
|
19
22
|
@mqtt.set_will("#{topic}/$state", "lost", retain: true, qos: 1)
|
@@ -40,11 +43,11 @@ module MQTT
|
|
40
43
|
"#{root_topic}/#{id}"
|
41
44
|
end
|
42
45
|
|
43
|
-
def node(id, *args
|
46
|
+
ruby2_keywords def node(id, *args)
|
44
47
|
raise ArgumentError, "Node '#{id}' already exists" if @nodes.key?(id)
|
45
48
|
|
46
49
|
init do |prior_state|
|
47
|
-
node = Node.new(self, id, *args
|
50
|
+
node = Node.new(self, id, *args)
|
48
51
|
|
49
52
|
@nodes[id] = node
|
50
53
|
yield node if block_given?
|
@@ -87,12 +90,13 @@ module MQTT
|
|
87
90
|
Thread.current.report_on_exception = false
|
88
91
|
|
89
92
|
mqtt.get do |packet|
|
93
|
+
logger&.debug("received packet at #{packet.topic} with payload #{packet.payload.inspect}")
|
90
94
|
match = packet.topic.match(topic_regex)
|
91
95
|
node = @nodes[match[:node]] if match
|
92
96
|
property = node[match[:property]] if node
|
93
97
|
|
94
98
|
unless property&.settable?
|
95
|
-
@
|
99
|
+
@out_of_band_topic_proc&.call(packet.topic, packet.payload)
|
96
100
|
next
|
97
101
|
end
|
98
102
|
|
data/lib/mqtt/homie/node.rb
CHANGED
@@ -17,9 +17,9 @@ module MQTT
|
|
17
17
|
"#{device.topic}/#{id}"
|
18
18
|
end
|
19
19
|
|
20
|
-
def property(*args,
|
20
|
+
ruby2_keywords def property(*args, &block)
|
21
21
|
device.init do |prior_state|
|
22
|
-
property = Property.new(self, *args,
|
22
|
+
property = Property.new(self, *args, &block)
|
23
23
|
raise ArgumentError, "Property '#{property.id}' already exists on '#{id}'" if @properties.key?(property.id)
|
24
24
|
@properties[property.id] = property
|
25
25
|
property.publish if prior_state == :ready
|
data/lib/mqtt/homie/property.rb
CHANGED
@@ -6,7 +6,7 @@ module MQTT
|
|
6
6
|
attr_reader :node, :datatype, :format, :unit, :value
|
7
7
|
|
8
8
|
def initialize(node, id, name, datatype, value = nil, format: nil, retained: true, unit: nil, &block)
|
9
|
-
raise ArgumentError, "Invalid Homie datatype" unless %
|
9
|
+
raise ArgumentError, "Invalid Homie datatype" unless %i[string integer float boolean enum color datetime duration].include?(datatype)
|
10
10
|
raise ArgumentError, "retained must be boolean" unless [true, false].include?(retained)
|
11
11
|
format = format.join(",") if format.is_a?(Array) && datatype == :enum
|
12
12
|
if %i{integer float}.include?(datatype) && format.is_a?(Range)
|
@@ -170,8 +170,10 @@ module MQTT
|
|
170
170
|
def publish_value
|
171
171
|
serialized = value
|
172
172
|
serialized = serialized&.iso8601 if %i[datetime duration].include?(datatype)
|
173
|
+
serialized = serialized.to_s
|
173
174
|
|
174
|
-
|
175
|
+
node.device.logger&.debug("publishing #{serialized.inspect} to #{topic}")
|
176
|
+
mqtt.publish(topic, serialized, retain: retained?, qos: 1)
|
175
177
|
end
|
176
178
|
end
|
177
179
|
end
|
data/lib/mqtt/homie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: homie-mqtt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt-ccutrer
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.1
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,23 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: ruby2_keywords
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.0.5
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.0.5
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: byebug
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|