cocoro-mqtt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 829c0ed1013a8f61cc02611d36a5036422e7fb72060c0a9b40b95448e0c87125
4
+ data.tar.gz: e50ffd67e68a416cd2e1ee8c04145c517077233de3156bd9d41b59da3ba93cdc
5
+ SHA512:
6
+ metadata.gz: d9c3ff5857f048fbe49c6346262d479af7f50668ba709c22d58e11881452d19ffd5e94cabc0f02602fec74b203b5639fa6c63bfe12122f9fb7574fc1514fc2c9
7
+ data.tar.gz: 9ed7bb19376bbb2b81daaa7b46d2a173123d25833044119edba3fc369fcb957038244d6cf54711cfbe4f8a32495f20b36159781c53300ed1c33a0ba7882d0757
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 100
16
+
17
+ Metrics/MethodLength:
18
+ Enabled: false
19
+
20
+ Metrics/ClassLength:
21
+ Max: 300
22
+
23
+ Metrics/ModuleLength:
24
+ Max: 200
25
+
26
+ Metrics/BlockLength:
27
+ Exclude:
28
+ - spec/**/*_spec.rb
29
+ - '*.gemspec'
30
+
31
+ Metrics/AbcSize:
32
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in cocoro-mqtt.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cocoro-mqtt (0.1.0)
5
+ cocoro (~> 0.1)
6
+ mqtt (~> 0.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ cocoro (0.1.0)
13
+ faraday (~> 1.8)
14
+ faraday-cookie_jar (>= 0.0.7)
15
+ faraday_middleware (~> 1.2)
16
+ diff-lcs (1.5.0)
17
+ domain_name (0.5.20190701)
18
+ unf (>= 0.0.5, < 1.0.0)
19
+ faraday (1.9.3)
20
+ faraday-em_http (~> 1.0)
21
+ faraday-em_synchrony (~> 1.0)
22
+ faraday-excon (~> 1.1)
23
+ faraday-httpclient (~> 1.0)
24
+ faraday-multipart (~> 1.0)
25
+ faraday-net_http (~> 1.0)
26
+ faraday-net_http_persistent (~> 1.0)
27
+ faraday-patron (~> 1.0)
28
+ faraday-rack (~> 1.0)
29
+ faraday-retry (~> 1.0)
30
+ ruby2_keywords (>= 0.0.4)
31
+ faraday-cookie_jar (0.0.7)
32
+ faraday (>= 0.8.0)
33
+ http-cookie (~> 1.0.0)
34
+ faraday-em_http (1.0.0)
35
+ faraday-em_synchrony (1.0.0)
36
+ faraday-excon (1.1.0)
37
+ faraday-httpclient (1.0.1)
38
+ faraday-multipart (1.0.2)
39
+ multipart-post (>= 1.2, < 3)
40
+ faraday-net_http (1.0.1)
41
+ faraday-net_http_persistent (1.2.0)
42
+ faraday-patron (1.0.0)
43
+ faraday-rack (1.0.0)
44
+ faraday-retry (1.0.3)
45
+ faraday_middleware (1.2.0)
46
+ faraday (~> 1.0)
47
+ http-cookie (1.0.4)
48
+ domain_name (~> 0.5)
49
+ mqtt (0.5.0)
50
+ multipart-post (2.1.1)
51
+ parallel (1.21.0)
52
+ parser (3.1.0.0)
53
+ ast (~> 2.4.1)
54
+ rainbow (3.0.0)
55
+ rake (13.0.6)
56
+ regexp_parser (2.2.0)
57
+ rexml (3.2.5)
58
+ rspec (3.10.0)
59
+ rspec-core (~> 3.10.0)
60
+ rspec-expectations (~> 3.10.0)
61
+ rspec-mocks (~> 3.10.0)
62
+ rspec-core (3.10.1)
63
+ rspec-support (~> 3.10.0)
64
+ rspec-expectations (3.10.1)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.10.0)
67
+ rspec-mocks (3.10.2)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.10.0)
70
+ rspec-support (3.10.3)
71
+ rubocop (1.24.1)
72
+ parallel (~> 1.10)
73
+ parser (>= 3.0.0.0)
74
+ rainbow (>= 2.2.2, < 4.0)
75
+ regexp_parser (>= 1.8, < 3.0)
76
+ rexml
77
+ rubocop-ast (>= 1.15.1, < 2.0)
78
+ ruby-progressbar (~> 1.7)
79
+ unicode-display_width (>= 1.4.0, < 3.0)
80
+ rubocop-ast (1.15.1)
81
+ parser (>= 3.0.1.1)
82
+ ruby-progressbar (1.11.0)
83
+ ruby2_keywords (0.0.5)
84
+ unf (0.1.4)
85
+ unf_ext
86
+ unf_ext (0.0.8)
87
+ unicode-display_width (2.1.0)
88
+
89
+ PLATFORMS
90
+ x86_64-darwin-20
91
+ x86_64-linux
92
+
93
+ DEPENDENCIES
94
+ cocoro-mqtt!
95
+ rake (~> 13.0)
96
+ rspec (~> 3.0)
97
+ rubocop (~> 1.7)
98
+
99
+ BUNDLED WITH
100
+ 2.3.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Tomasz Szczęśniak-Szlagowski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Cocoro::Mqtt
2
+
3
+ This is a Ruby gem for exposing your Cocoro Air-compatible device via MQTT.
4
+ It supports Home Assistant's discovery and can be used either as a library or executable.
5
+
6
+ Be aware that this is totally unofficial, not affiliated with SHARP in any way.
7
+ The moment they change their APIs, this gem may stop working.
8
+
9
+ ## Installation
10
+
11
+ To use it as a library, add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'cocoro-mqtt'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or if you want to run it as a standalone app, install it yourself as:
22
+
23
+ $ gem install cocoro-mqtt
24
+
25
+ ## Usage
26
+
27
+ The tricky part is that you need to
28
+ [get the credentials first](https://github.com/spect88/cocoro#getting-the-api-credentials).
29
+
30
+
31
+ Running the gem standalone:
32
+ ```sh
33
+ $ APP_SECRET=... TERMINAL_APP_ID_KEY=... MQTT_URL=... cocoro-mqtt
34
+ ```
35
+
36
+ Using it from code:
37
+ ```ruby
38
+ require "cocoro/mqtt"
39
+ require "mqtt"
40
+ require "logger"
41
+
42
+ app_secret = "..."
43
+ terminal_app_id_key = "..."
44
+ mqtt_url = "..."
45
+
46
+ cocoro = Cocoro::Client.new(app_secret: app_secret, terminal_app_id_key: terminal_app_id_key)
47
+ cocoro.login
48
+
49
+ mqtt = MQTT::Client.new(mqtt_url)
50
+
51
+ server = Cocoro::Mqtt.new(cocoro_client: cocoro, mqtt_client: mqtt)
52
+ server.logger.level = Logger::INFO
53
+ server.start
54
+ ```
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+
60
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cocoro-mqtt.
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "cocoro/mqtt"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/cocoro/mqtt/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "cocoro-mqtt"
7
+ spec.version = Cocoro::Mqtt::VERSION
8
+ spec.authors = ["Tomasz Szczęśniak-Szlagowski"]
9
+ spec.email = ["spect88@gmail.com"]
10
+
11
+ spec.summary = "Unofficial Cocoro Air API to MQTT bridge"
12
+ spec.description = "This is a bridge exposing your Cocoro Air compatible devices on MQTT. " \
13
+ "Not affiliated with SHARP in any way - use at your own risk"
14
+ spec.homepage = "https://github.com/spect88/cocoro-mqtt"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 2.5.0"
17
+
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+ spec.metadata["rubygems_mfa_required"] = "true"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/spect88/cocoro-mqtt"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject do |f|
28
+ (f == __FILE__) || f.match(
29
+ %r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}
30
+ )
31
+ end
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ # Uncomment to register a new dependency of your gem
38
+ spec.add_dependency "cocoro", "~> 0.1"
39
+ spec.add_dependency "mqtt", "~> 0.5"
40
+
41
+ spec.add_development_dependency "rake", "~> 13.0"
42
+ spec.add_development_dependency "rspec", "~> 3.0"
43
+ spec.add_development_dependency "rubocop", "~> 1.7"
44
+ # For more information and examples about making a new gem, checkout our
45
+ # guide at: https://bundler.io/guides/creating_gem.html
46
+ end
data/exe/cocoro-mqtt ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "cocoro/mqtt"
5
+ require "mqtt"
6
+ require "logger"
7
+
8
+ app_secret, terminal_app_id_key, mqtt_url =
9
+ ENV.values_at("APP_SECRET", "TERMINAL_APP_ID_KEY", "MQTT_URL")
10
+
11
+ if [app_secret, terminal_app_id_key, mqtt_url].any?(&:nil?)
12
+ warn <<~MSG
13
+ You need to set the required environment variables:
14
+ - APP_SECRET
15
+ - TERMINAL_APP_ID_KEY
16
+ - MQTT_URL
17
+ MSG
18
+ exit 1
19
+ end
20
+
21
+ cocoro = Cocoro::Client.new(app_secret: app_secret, terminal_app_id_key: terminal_app_id_key)
22
+ cocoro.login
23
+ mqtt = MQTT::Client.new(mqtt_url)
24
+ server = Cocoro::Mqtt.new(cocoro_client: cocoro, mqtt_client: mqtt)
25
+ server.logger.level = Logger::INFO
26
+ server.start
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocoro
4
+ class Mqtt
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,239 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cocoro"
4
+ require "logger"
5
+
6
+ require_relative "mqtt/version"
7
+
8
+ module Cocoro
9
+ # A bridge between Cocoro Air API and MQTT
10
+ class Mqtt
11
+ DEFAULT_INTERVAL = 30 # seconds
12
+
13
+ attr_accessor :logger
14
+
15
+ def initialize(cocoro_client:, mqtt_client:, interval: DEFAULT_INTERVAL, logger: nil)
16
+ @cocoro = cocoro_client
17
+ @mqtt = mqtt_client
18
+ @interval = interval
19
+ @logger = logger || Logger.new($stdout).tap do |l|
20
+ l.level = Logger::WARN
21
+ end
22
+ @mutex = Mutex.new
23
+ end
24
+
25
+ def start
26
+ @mqtt.connect do |client|
27
+ @cocoro.devices.each do |device|
28
+ subscribe_to_device_command_topics(device, client)
29
+ make_device_discoverable(device, client)
30
+ end
31
+ subscriber = Thread.new { keep_handling_commands(client) }
32
+ publisher = Thread.new { keep_publishing_state_updates(client) }
33
+ [subscriber, publisher].each(&:join)
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ def keep_publishing_state_updates(client)
40
+ loop do
41
+ @cocoro.devices.each do |device|
42
+ refresh_device_state(device, client)
43
+ end
44
+ sleep @interval
45
+ end
46
+ end
47
+
48
+ def refresh_device_state(device, client)
49
+ # Synchronizing to make sure we're not spamming the API by fetching
50
+ # from 2 threads at once
51
+ @mutex.synchronize do
52
+ @logger.info { "Fetching #{device.name} status..." }
53
+ status = device.fetch_status!
54
+ @logger.info { status.to_h }
55
+ publish_device_state(device, client, status)
56
+ end
57
+ rescue Cocoro::Error => e
58
+ @logger.error { "Couldn't fetch #{device.name} status: #{e}" }
59
+ end
60
+
61
+ def keep_handling_commands(client)
62
+ client.get do |topic, message|
63
+ handle_command(client, topic, message)
64
+ end
65
+ end
66
+
67
+ def handle_command(client, topic, message)
68
+ _, id, target = topic.split("/")
69
+ device = @cocoro.devices.find { |d| d.echonet_node == id }
70
+ if device.nil?
71
+ @logger.error { "Unknown device: #{id} (#{topic})" }
72
+ return
73
+ end
74
+
75
+ case target
76
+ when "on"
77
+ device.set_power_on!(message == "ON")
78
+ when "humidifier"
79
+ device.set_humidifier_on!(message == "ON")
80
+ when "mode"
81
+ device.set_air_volume!(message)
82
+ else
83
+ @logger.error { "Unknown command target: #{target} (#{topic})" }
84
+ return
85
+ end
86
+ refresh_device_state(device, client)
87
+ rescue Cocoro::Error => e
88
+ @logger.error { "Couldn't handle '#{message}' at '#{topic}': #{e}" }
89
+ end
90
+
91
+ def publish_device_state(device, client, status)
92
+ # TODO: availability
93
+ id = device.echonet_node
94
+ client.publish("cocoro/#{id}/on/state", status.power_on? ? "ON" : "OFF")
95
+ client.publish("cocoro/#{id}/mode/state", status.air_volume)
96
+ client.publish("cocoro/#{id}/humidifier/state", status.humidifier_on? ? "ON" : "OFF")
97
+ client.publish("cocoro/#{id}/light/state", status.light_detected? ? "ON" : "OFF")
98
+ client.publish("cocoro/#{id}/empty_water_tank/state", status.enough_water? ? "OFF" : "ON")
99
+ client.publish("cocoro/#{id}/temperature/state", status.temperature)
100
+ client.publish("cocoro/#{id}/humidity/state", status.humidity)
101
+ client.publish("cocoro/#{id}/air_cleaned/state", status.total_air_cleaned)
102
+ client.publish("cocoro/#{id}/pm25/state", status.pm25)
103
+ client.publish("cocoro/#{id}/odor/state", status.smell)
104
+ client.publish("cocoro/#{id}/dust/state", status.dust)
105
+ client.publish("cocoro/#{id}/overall_dirtiness/state", status.overall_cleanliness)
106
+ end
107
+
108
+ def subscribe_to_device_command_topics(device, client)
109
+ id = device.echonet_node
110
+ topics = %W[
111
+ cocoro/#{id}/on/set
112
+ cocoro/#{id}/mode/set
113
+ cocoro/#{id}/humidifier/set
114
+ ]
115
+ client.subscribe(*topics)
116
+ end
117
+
118
+ def make_device_discoverable(device, client)
119
+ id = device.echonet_node
120
+ client.publish(
121
+ "homeassistant/fan/airpurifier/#{id}/config",
122
+ JSON.dump(
123
+ "~" => "cocoro/#{id}",
124
+ "name" => "#{device.name} Air Purifier",
125
+ "device" => {
126
+ "manufacturer" => "SHARP",
127
+ "name" => device.name,
128
+ "identifiers" => [id]
129
+ },
130
+ "icon" => "mdi:air-purifier",
131
+ "state_topic" => "~/on/state",
132
+ "command_topic" => "~/on/set",
133
+ "preset_mode_state_topic" => "~/mode/state",
134
+ "preset_mode_command_topic" => "~/mode/set",
135
+ "preset_modes" => %w[auto night pollen quiet medium strong omakase powerful]
136
+ )
137
+ )
138
+ client.publish(
139
+ "homeassistant/switch/humidifier/#{id}/config",
140
+ JSON.dump(
141
+ "~" => "cocoro/#{id}/humidifier",
142
+ "name" => "#{device.name} Humidifier",
143
+ "state_topic" => "~/state",
144
+ "command_topic" => "~/set",
145
+ "icon" => "mdi:air-humidifier"
146
+ )
147
+ )
148
+ client.publish(
149
+ "homeassistant/binary_sensor/light/#{id}/config",
150
+ JSON.dump(
151
+ "~" => "cocoro/#{id}/light",
152
+ "name" => "#{device.name} Light",
153
+ "device_class" => "light",
154
+ "state_topic" => "~/state"
155
+ )
156
+ )
157
+ client.publish(
158
+ "homeassistant/binary_sensor/empty_water_tank/#{id}/config",
159
+ JSON.dump(
160
+ "~" => "cocoro/#{id}/empty_water_tank",
161
+ "name" => "#{device.name} Empty Water Tank",
162
+ "device_class" => "problem",
163
+ "state_topic" => "~/state",
164
+ "icon" => "mdi:water"
165
+ )
166
+ )
167
+ client.publish(
168
+ "homeassistant/sensor/temperature/#{id}/config",
169
+ JSON.dump(
170
+ "~" => "cocoro/#{id}/temperature",
171
+ "name" => "#{device.name} Temperature",
172
+ "device_class" => "temperature",
173
+ "state_topic" => "~/state",
174
+ "unit_of_measurement" => "°C"
175
+ )
176
+ )
177
+ client.publish(
178
+ "homeassistant/sensor/humidity/#{id}/config",
179
+ JSON.dump(
180
+ "~" => "cocoro/#{id}/humidity",
181
+ "name" => "#{device.name} Humidity",
182
+ "device_class" => "humidity",
183
+ "state_topic" => "~/state",
184
+ "unit_of_measurement" => "%"
185
+ )
186
+ )
187
+ client.publish(
188
+ "homeassistant/sensor/air_cleaned/#{id}/config",
189
+ JSON.dump(
190
+ "~" => "cocoro/#{id}/air_cleaned",
191
+ "name" => "#{device.name} Total Air Cleaned",
192
+ "device_class" => "gas",
193
+ "state_topic" => "~/state",
194
+ "unit_of_measurement" => "m³"
195
+ )
196
+ )
197
+ client.publish(
198
+ "homeassistant/sensor/pm25/#{id}/config",
199
+ JSON.dump(
200
+ "~" => "cocoro/#{id}/pm25",
201
+ "name" => "#{device.name} PM 2.5",
202
+ "device_class" => "pm25",
203
+ "state_topic" => "~/state",
204
+ "unit_of_measurement" => "µg/m³"
205
+ )
206
+ )
207
+ client.publish(
208
+ "homeassistant/sensor/odor/#{id}/config",
209
+ JSON.dump(
210
+ "~" => "cocoro/#{id}/odor",
211
+ "name" => "#{device.name} Odor",
212
+ "state_topic" => "~/state",
213
+ "icon" => "mdi:scent",
214
+ "unit_of_measurement" => "%"
215
+ )
216
+ )
217
+ client.publish(
218
+ "homeassistant/sensor/dust/#{id}/config",
219
+ JSON.dump(
220
+ "~" => "cocoro/#{id}/dust",
221
+ "name" => "#{device.name} Dust",
222
+ "state_topic" => "~/state",
223
+ "icon" => "mdi:broom",
224
+ "unit_of_measurement" => "%"
225
+ )
226
+ )
227
+ client.publish(
228
+ "homeassistant/sensor/overall_dirtiness/#{id}/config",
229
+ JSON.dump(
230
+ "~" => "cocoro/#{id}/overall_dirtiness",
231
+ "name" => "#{device.name} Overall Air Dirtiness",
232
+ "state_topic" => "~/state",
233
+ "icon" => "mdi:delete",
234
+ "unit_of_measurement" => "%"
235
+ )
236
+ )
237
+ end
238
+ end
239
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoro-mqtt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomasz Szczęśniak-Szlagowski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cocoro
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mqtt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ description: This is a bridge exposing your Cocoro Air compatible devices on MQTT.
84
+ Not affiliated with SHARP in any way - use at your own risk
85
+ email:
86
+ - spect88@gmail.com
87
+ executables:
88
+ - cocoro-mqtt
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - cocoro-mqtt.gemspec
102
+ - exe/cocoro-mqtt
103
+ - lib/cocoro/mqtt.rb
104
+ - lib/cocoro/mqtt/version.rb
105
+ homepage: https://github.com/spect88/cocoro-mqtt
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ allowed_push_host: https://rubygems.org
110
+ rubygems_mfa_required: 'true'
111
+ homepage_uri: https://github.com/spect88/cocoro-mqtt
112
+ source_code_uri: https://github.com/spect88/cocoro-mqtt
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 2.5.0
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.1.6
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Unofficial Cocoro Air API to MQTT bridge
132
+ test_files: []