homie-mqtt 1.3.0 → 1.4.0
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/property.rb +24 -3
- data/lib/mqtt/homie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adb5e19afec9a2e2d3525ea4879992306f2cd56632139bbc4d691ccc1e2b6bbb
|
4
|
+
data.tar.gz: ff164da43b91048841edef8488e654108d0c566dfe4e0b8150a1cff423b36214
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4cd79531f71ce7cc077b7f06acd181dd41694494eacab571323fb3930755a10aa57254b1d81dfec3d66ab880b39adc5b21af62ce8c66e84304ca52bf2021fc6
|
7
|
+
data.tar.gz: a11b7bf36fdfb34677d9becdb733ddd4c53cf0ed64f51575b44d257e37b04bd7c07599b0ca6c37b0c7da70466d0b3389373b2d9795327947ba93dd2d14761528
|
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 %s{string integer float boolean enum color}
|
9
|
+
raise ArgumentError, "Invalid Homie datatype" unless %s{string integer float boolean enum color datetime duration}
|
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)
|
@@ -51,7 +51,7 @@ module MQTT
|
|
51
51
|
def value=(value)
|
52
52
|
if @value != value
|
53
53
|
@value = value if retained?
|
54
|
-
|
54
|
+
publish_value if @published
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -109,6 +109,18 @@ module MQTT
|
|
109
109
|
elsif format == 'hsv'
|
110
110
|
return if value.first > 360 || value[1..2].max > 100
|
111
111
|
end
|
112
|
+
when :datetime
|
113
|
+
begin
|
114
|
+
value = Time.parse(value)
|
115
|
+
rescue ArgumentError
|
116
|
+
return
|
117
|
+
end
|
118
|
+
when :duration
|
119
|
+
begin
|
120
|
+
value = ActiveSupport::Duration.parse(value)
|
121
|
+
rescue ActiveSupport::Duration::ISO8601Parser::ParsingError
|
122
|
+
return
|
123
|
+
end
|
112
124
|
end
|
113
125
|
|
114
126
|
@block.arity == 2 ? @block.call(value, self) : @block.call(value)
|
@@ -128,7 +140,7 @@ module MQTT
|
|
128
140
|
mqtt.publish("#{topic}/$settable", "true", retain: true, qos: 1) if settable?
|
129
141
|
mqtt.publish("#{topic}/$retained", "false", retain: true, qos: 1) unless retained?
|
130
142
|
mqtt.publish("#{topic}/$unit", unit, retain: true, qos: 1) if unit
|
131
|
-
|
143
|
+
publish_value unless value.nil?
|
132
144
|
subscribe
|
133
145
|
end
|
134
146
|
|
@@ -152,6 +164,15 @@ module MQTT
|
|
152
164
|
mqtt.unsubscribe("#{topic}/set") if settable?
|
153
165
|
mqtt.publish(topic, retain: retained?, qos: 0) if !value.nil? && retained?
|
154
166
|
end
|
167
|
+
|
168
|
+
private
|
169
|
+
|
170
|
+
def publish_value
|
171
|
+
serialized = value
|
172
|
+
serialized = serialized&.iso8601 if %i[datetime duration].include?(datatype)
|
173
|
+
|
174
|
+
mqtt.publish(topic, serialized.to_s, retain: retained?, qos: 1)
|
175
|
+
end
|
155
176
|
end
|
156
177
|
end
|
157
178
|
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
|
+
version: 1.4.0
|
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-07-
|
11
|
+
date: 2021-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt-ccutrer
|