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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64cfaf8cbbff82a3059c8fcfa639efc39f006241cd79aaadb6bce200eb82a9cc
4
- data.tar.gz: d9045a9c729515c2912aeb11b20c5ecad9885b7e0f4df95263e688d74d72f077
3
+ metadata.gz: adb5e19afec9a2e2d3525ea4879992306f2cd56632139bbc4d691ccc1e2b6bbb
4
+ data.tar.gz: ff164da43b91048841edef8488e654108d0c566dfe4e0b8150a1cff423b36214
5
5
  SHA512:
6
- metadata.gz: 04ea1126fe4310cc758ddf23fe859f380a0250baf0998a1fab3d695c6f18e6087028dd35de8f619414ec0512d46ac24fb6fb91cae2821729c18b2a91b209455d
7
- data.tar.gz: 6200b420bed16a9267cdde8f7192c52d8cd72568dcb72e35247620bd4b71031069a12986b41290329c199bfbf0fc7abdbf25a81d8fdbe1bcce7906b09a883673
6
+ metadata.gz: b4cd79531f71ce7cc077b7f06acd181dd41694494eacab571323fb3930755a10aa57254b1d81dfec3d66ab880b39adc5b21af62ce8c66e84304ca52bf2021fc6
7
+ data.tar.gz: a11b7bf36fdfb34677d9becdb733ddd4c53cf0ed64f51575b44d257e37b04bd7c07599b0ca6c37b0c7da70466d0b3389373b2d9795327947ba93dd2d14761528
@@ -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
- mqtt.publish(topic, value.to_s, retain: retained?, qos: 1) if @published
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
- mqtt.publish(topic, value.to_s, retain: retained?, qos: 1) unless value.nil?
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module MQTT
4
4
  module Homie
5
- VERSION = '1.3.0'
5
+ VERSION = '1.4.0'
6
6
  end
7
7
  end
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.3.0
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-16 00:00:00.000000000 Z
11
+ date: 2021-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mqtt-ccutrer