cocoro-mqtt 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 829c0ed1013a8f61cc02611d36a5036422e7fb72060c0a9b40b95448e0c87125
4
- data.tar.gz: e50ffd67e68a416cd2e1ee8c04145c517077233de3156bd9d41b59da3ba93cdc
3
+ metadata.gz: 17ad5dcb799245f106467a794c3a47d0b6ec421e56431e009ba4d7095a094519
4
+ data.tar.gz: 1c1c237183c7ce207ff74e342828754fea895e052ee98568c941aff2e0bfd845
5
5
  SHA512:
6
- metadata.gz: d9c3ff5857f048fbe49c6346262d479af7f50668ba709c22d58e11881452d19ffd5e94cabc0f02602fec74b203b5639fa6c63bfe12122f9fb7574fc1514fc2c9
7
- data.tar.gz: 9ed7bb19376bbb2b81daaa7b46d2a173123d25833044119edba3fc369fcb957038244d6cf54711cfbe4f8a32495f20b36159781c53300ed1c33a0ba7882d0757
6
+ metadata.gz: 1880a2e64f6ed06a1e6f16f66ca65b5016d18167cf93f7ea241742026737a8d65964f811070063322c891abbc8e121b4921372332afb85df32ad5dd0b9649d70
7
+ data.tar.gz: dfa32f243c7a21e67d3244da1c8edb01f4f505e2e618a3c86b3ac217b21abf136688b5a0307bfb493a01d03ebc4173fba884266ba1563093cc5d5d8917377fa3
data/Gemfile.lock CHANGED
@@ -2,14 +2,14 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  cocoro-mqtt (0.1.0)
5
- cocoro (~> 0.1)
5
+ cocoro (~> 0.2)
6
6
  mqtt (~> 0.5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  ast (2.4.2)
12
- cocoro (0.1.0)
12
+ cocoro (0.2.0)
13
13
  faraday (~> 1.8)
14
14
  faraday-cookie_jar (>= 0.0.7)
15
15
  faraday_middleware (~> 1.2)
data/cocoro-mqtt.gemspec CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.require_paths = ["lib"]
36
36
 
37
37
  # Uncomment to register a new dependency of your gem
38
- spec.add_dependency "cocoro", "~> 0.1"
38
+ spec.add_dependency "cocoro", "~> 0.2"
39
39
  spec.add_dependency "mqtt", "~> 0.5"
40
40
 
41
41
  spec.add_development_dependency "rake", "~> 13.0"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cocoro
4
4
  class Mqtt
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
data/lib/cocoro/mqtt.rb CHANGED
@@ -24,7 +24,7 @@ module Cocoro
24
24
 
25
25
  def start
26
26
  @mqtt.connect do |client|
27
- @cocoro.devices.each do |device|
27
+ air_cleaners.each do |device|
28
28
  subscribe_to_device_command_topics(device, client)
29
29
  make_device_discoverable(device, client)
30
30
  end
@@ -36,9 +36,13 @@ module Cocoro
36
36
 
37
37
  protected
38
38
 
39
+ def air_cleaners
40
+ @air_cleaners ||= @cocoro.devices.select { |d| d.type == "AIR_CLEANER" }
41
+ end
42
+
39
43
  def keep_publishing_state_updates(client)
40
44
  loop do
41
- @cocoro.devices.each do |device|
45
+ air_cleaners.each do |device|
42
46
  refresh_device_state(device, client)
43
47
  end
44
48
  sleep @interval
@@ -66,12 +70,13 @@ module Cocoro
66
70
 
67
71
  def handle_command(client, topic, message)
68
72
  _, id, target = topic.split("/")
69
- device = @cocoro.devices.find { |d| d.echonet_node == id }
73
+ device = air_cleaners.find { |d| d.echonet_node == id }
70
74
  if device.nil?
71
75
  @logger.error { "Unknown device: #{id} (#{topic})" }
72
76
  return
73
77
  end
74
78
 
79
+ @logger.info { "Executing '#{message}' command at '#{topic}'" }
75
80
  case target
76
81
  when "on"
77
82
  device.set_power_on!(message == "ON")
@@ -89,7 +94,6 @@ module Cocoro
89
94
  end
90
95
 
91
96
  def publish_device_state(device, client, status)
92
- # TODO: availability
93
97
  id = device.echonet_node
94
98
  client.publish("cocoro/#{id}/on/state", status.power_on? ? "ON" : "OFF")
95
99
  client.publish("cocoro/#{id}/mode/state", status.air_volume)
@@ -100,9 +104,9 @@ module Cocoro
100
104
  client.publish("cocoro/#{id}/humidity/state", status.humidity)
101
105
  client.publish("cocoro/#{id}/air_cleaned/state", status.total_air_cleaned)
102
106
  client.publish("cocoro/#{id}/pm25/state", status.pm25)
103
- client.publish("cocoro/#{id}/odor/state", status.smell)
107
+ client.publish("cocoro/#{id}/odor/state", status.odor)
104
108
  client.publish("cocoro/#{id}/dust/state", status.dust)
105
- client.publish("cocoro/#{id}/overall_dirtiness/state", status.overall_cleanliness)
109
+ client.publish("cocoro/#{id}/overall_dirtiness/state", status.overall_dirtiness)
106
110
  end
107
111
 
108
112
  def subscribe_to_device_command_topics(device, client)
@@ -117,16 +121,24 @@ module Cocoro
117
121
 
118
122
  def make_device_discoverable(device, client)
119
123
  id = device.echonet_node
124
+ device_description = {
125
+ "manufacturer" => device.maker,
126
+ "model" => device.model,
127
+ "name" => device.name,
128
+ "identifiers" => [id]
129
+ }
130
+ availabile_only_when_on = {
131
+ "topic" => "cocoro/#{id}/on/state",
132
+ "payload_available" => "ON",
133
+ "payload_not_available" => "OFF"
134
+ }
120
135
  client.publish(
121
136
  "homeassistant/fan/airpurifier/#{id}/config",
122
137
  JSON.dump(
123
138
  "~" => "cocoro/#{id}",
124
139
  "name" => "#{device.name} Air Purifier",
125
- "device" => {
126
- "manufacturer" => "SHARP",
127
- "name" => device.name,
128
- "identifiers" => [id]
129
- },
140
+ "unique_id" => "#{id}_airpurifier",
141
+ "device" => device_description,
130
142
  "icon" => "mdi:air-purifier",
131
143
  "state_topic" => "~/on/state",
132
144
  "command_topic" => "~/on/set",
@@ -140,6 +152,9 @@ module Cocoro
140
152
  JSON.dump(
141
153
  "~" => "cocoro/#{id}/humidifier",
142
154
  "name" => "#{device.name} Humidifier",
155
+ "unique_id" => "#{id}_humidifier",
156
+ "device" => device_description,
157
+ "availability" => [availabile_only_when_on],
143
158
  "state_topic" => "~/state",
144
159
  "command_topic" => "~/set",
145
160
  "icon" => "mdi:air-humidifier"
@@ -150,6 +165,8 @@ module Cocoro
150
165
  JSON.dump(
151
166
  "~" => "cocoro/#{id}/light",
152
167
  "name" => "#{device.name} Light",
168
+ "unique_id" => "#{id}_light",
169
+ "device" => device_description,
153
170
  "device_class" => "light",
154
171
  "state_topic" => "~/state"
155
172
  )
@@ -159,6 +176,8 @@ module Cocoro
159
176
  JSON.dump(
160
177
  "~" => "cocoro/#{id}/empty_water_tank",
161
178
  "name" => "#{device.name} Empty Water Tank",
179
+ "unique_id" => "#{id}_empty_water_tank",
180
+ "device" => device_description,
162
181
  "device_class" => "problem",
163
182
  "state_topic" => "~/state",
164
183
  "icon" => "mdi:water"
@@ -169,6 +188,9 @@ module Cocoro
169
188
  JSON.dump(
170
189
  "~" => "cocoro/#{id}/temperature",
171
190
  "name" => "#{device.name} Temperature",
191
+ "unique_id" => "#{id}_temperature",
192
+ "device" => device_description,
193
+ "availability" => [availabile_only_when_on],
172
194
  "device_class" => "temperature",
173
195
  "state_topic" => "~/state",
174
196
  "unit_of_measurement" => "°C"
@@ -179,6 +201,9 @@ module Cocoro
179
201
  JSON.dump(
180
202
  "~" => "cocoro/#{id}/humidity",
181
203
  "name" => "#{device.name} Humidity",
204
+ "unique_id" => "#{id}_humidity",
205
+ "device" => device_description,
206
+ "availability" => [availabile_only_when_on],
182
207
  "device_class" => "humidity",
183
208
  "state_topic" => "~/state",
184
209
  "unit_of_measurement" => "%"
@@ -189,6 +214,8 @@ module Cocoro
189
214
  JSON.dump(
190
215
  "~" => "cocoro/#{id}/air_cleaned",
191
216
  "name" => "#{device.name} Total Air Cleaned",
217
+ "unique_id" => "#{id}_air_cleaned",
218
+ "device" => device_description,
192
219
  "device_class" => "gas",
193
220
  "state_topic" => "~/state",
194
221
  "unit_of_measurement" => "m³"
@@ -199,6 +226,9 @@ module Cocoro
199
226
  JSON.dump(
200
227
  "~" => "cocoro/#{id}/pm25",
201
228
  "name" => "#{device.name} PM 2.5",
229
+ "unique_id" => "#{id}_pm25",
230
+ "device" => device_description,
231
+ "availability" => [availabile_only_when_on],
202
232
  "device_class" => "pm25",
203
233
  "state_topic" => "~/state",
204
234
  "unit_of_measurement" => "µg/m³"
@@ -209,6 +239,9 @@ module Cocoro
209
239
  JSON.dump(
210
240
  "~" => "cocoro/#{id}/odor",
211
241
  "name" => "#{device.name} Odor",
242
+ "unique_id" => "#{id}_odor",
243
+ "device" => device_description,
244
+ "availability" => [availabile_only_when_on],
212
245
  "state_topic" => "~/state",
213
246
  "icon" => "mdi:scent",
214
247
  "unit_of_measurement" => "%"
@@ -219,6 +252,9 @@ module Cocoro
219
252
  JSON.dump(
220
253
  "~" => "cocoro/#{id}/dust",
221
254
  "name" => "#{device.name} Dust",
255
+ "unique_id" => "#{id}_dust",
256
+ "device" => device_description,
257
+ "availability" => [availabile_only_when_on],
222
258
  "state_topic" => "~/state",
223
259
  "icon" => "mdi:broom",
224
260
  "unit_of_measurement" => "%"
@@ -229,6 +265,9 @@ module Cocoro
229
265
  JSON.dump(
230
266
  "~" => "cocoro/#{id}/overall_dirtiness",
231
267
  "name" => "#{device.name} Overall Air Dirtiness",
268
+ "unique_id" => "#{id}_overall_dirtiness",
269
+ "device" => device_description,
270
+ "availability" => [availabile_only_when_on],
232
271
  "state_topic" => "~/state",
233
272
  "icon" => "mdi:delete",
234
273
  "unit_of_measurement" => "%"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoro-mqtt
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
  - Tomasz Szczęśniak-Szlagowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2022-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoro
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '0.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.1'
26
+ version: '0.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mqtt
29
29
  requirement: !ruby/object:Gem::Requirement