purpleair 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/exe/purpleair_mqtt_bridge +112 -19
  3. metadata +21 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b9e42984ee91df25030728bbe8afd7b4181f212a51408625cf20422b10d8bf3
4
- data.tar.gz: 1b1ff17dd8ca0ead8b40b910bebbfe9d7954f5966c24217b2c5eacf2416c6d13
3
+ metadata.gz: 060b300e03f93347681d274759857922d8455b0656163c7d41cea67451558323
4
+ data.tar.gz: 79f6d753281474e92b9089b0998a0244e07032d31073bfc6ecc58731715a2bf1
5
5
  SHA512:
6
- metadata.gz: d8730b6073ee00126cf5f93c87d62a6e90f009e5762201a0d22ffc5f71189b52ea001d54d488ee1320cedd76763808d040e7ef5d8d2bc4d598f367eb466f0d67
7
- data.tar.gz: 9614f9b96468cf4698b415c4de8a1bf3946fc998f3001aaabce1c1469dca58d7608e5fa0371bd175b996d6e5cc0c0f82ef5b9ce7fd0d8cb6a4935a6f3e4f2d55
6
+ metadata.gz: 91296a0d880f6493ec018ae1d13d067be69a599a70079b11074a21a14e4530233f501d053ce30e7315e8c78a97651cb3664bf32d4b50deb227caff5987e77e08
7
+ data.tar.gz: 19ba9b97408f248fe315d5f7ae96b2820f4ec4d286f92c0c3f9bfe20babce4ccff258c99ffbd194fcf0639b450d015a46b398de7c973971b0c3808d8a594b6e2
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "faraday_middleware"
5
- require "homie-mqtt"
5
+ require "mqtt-homeassistant"
6
6
  require "optparse"
7
7
 
8
8
  refresh = 30.0
@@ -36,13 +36,53 @@ end
36
36
  data = purple.get.body
37
37
 
38
38
  homie = MQTT::Homie::Device.new(MQTT::Homie.escape_id(data["Geo"]), "PurpleAir Sensor", mqtt: ARGV[1])
39
+ homie.home_assistant_device = {
40
+ manufacturer: "PurpleAir, Inc.",
41
+ sw_version: data["version"],
42
+ model: data["hardwarediscovered"]
43
+ }
44
+
39
45
  device = homie.node("device", "Device", "Device")
40
- device.property("temperature", "Current Temperature", :integer, data["current_temp_f"], unit: "°F")
41
- device.property("relative-humidity", "Current Relative Humidity", :integer, data["current_humidity"],
42
- format: 0..100, unit: "%")
43
- device.property("dewpoint", "Current Dew Point", :integer, data["current_dewpoint_f"], unit: "°F")
44
- device.property("pressure", "Barometric Pressure", :integer, data["pressure"], unit: "hPA")
45
- device.property("rssi", "WiFi RSSI", :integer, data["rssi"], unit: "dB")
46
+ device.property("temperature",
47
+ "Current Temperature",
48
+ :integer,
49
+ data["current_temp_f"],
50
+ unit: "°F",
51
+ hass: { sensor: { device_class: :temperature,
52
+ state_class: :measurement } })
53
+ device.property("relative-humidity",
54
+ "Current Relative Humidity",
55
+ :integer,
56
+ data["current_humidity"],
57
+ format: 0..100,
58
+ unit: "%",
59
+ hass: { sensor: { device_class: :humidity,
60
+ state_class: :measurement } })
61
+ device.property("dewpoint",
62
+ "Current Dew Point",
63
+ :integer,
64
+ data["current_dewpoint_f"],
65
+ unit: "°F",
66
+ hass: { sensor: { device_class: :temperature,
67
+ icon: "mdi:water-opacity",
68
+ state_class: :measurement } })
69
+ device.property("pressure",
70
+ "Barometric Pressure",
71
+ :integer,
72
+ data["pressure"],
73
+ unit: "hPA",
74
+ hass: { sensor: { device_class: :pressure,
75
+ state_class: :measurement } })
76
+ device.property("rssi",
77
+ "WiFi RSSI",
78
+ :integer,
79
+ data["rssi"],
80
+ unit: "dB",
81
+ hass: { sensor: { device_class: :signal_strength,
82
+ state_class: :measurement,
83
+ entity_category: :diagnostic } })
84
+
85
+ CHANNELS = %w[a b].freeze
46
86
 
47
87
  FIELDS = %w[
48
88
  pm2.5_aqi
@@ -66,19 +106,72 @@ def get_fields(data, channel_id)
66
106
  result
67
107
  end
68
108
 
69
- %w[a b].each do |channel_id|
109
+ CHANNELS.each do |channel_id|
70
110
  fields = get_fields(data, channel_id)
71
111
  channel = homie.node(channel_id, "Sensor Channel #{channel_id.upcase}", "Air Sensor")
72
- channel.property("pm2-5-aqi", "PM2.5 AQI", :integer, fields["pm2.5_aqi"])
73
- channel.property("pm1-0-atm", "PM1.0", :float, fields["pm1_0_atm"], unit: "µg/m3")
74
- channel.property("pm2-5-atm", "PM2.5", :float, fields["pm2_5_atm"], unit: "µg/m3")
75
- channel.property("pm10-0-atm", "PM10", :float, fields["pm10_0_atm"], unit: "µg/m3")
76
- channel.property("p-0-3-um", "# particles >= 0.3µm per decileter", :float, fields["p_0_3_um"])
77
- channel.property("p-0-5-um", "# particles >= 0.5µm per decileter", :float, fields["p_0_5_um"])
78
- channel.property("p-1-0-um", "# particles >= 1.0µm per decileter", :float, fields["p_1_0_um"])
79
- channel.property("p-2-5-um", "# particles >= 2.5µm per decileter", :float, fields["p_2_5_um"])
80
- channel.property("p-5-0-um", "# particles >= 5.0µm per decileter", :float, fields["p_5_0_um"])
81
- channel.property("p-10-0-um", "# particles >= 10µm per decileter", :float, fields["p_10_0_um"])
112
+ channel.property("pm2-5-aqi",
113
+ "PM2.5 AQI",
114
+ :integer,
115
+ fields["pm2.5_aqi"],
116
+ hass: { sensor: { device_class: :aqi,
117
+ state_class: :measurement } })
118
+ channel.property("pm1-0-atm",
119
+ "PM1.0",
120
+ :float,
121
+ fields["pm1_0_atm"],
122
+ unit: "µg/m3",
123
+ hass: { sensor: { device_class: :pm1,
124
+ state_class: :measurement } })
125
+ channel.property("pm2-5-atm",
126
+ "PM2.5",
127
+ :float,
128
+ fields["pm2_5_atm"],
129
+ unit: "µg/m3",
130
+ hass: { sensor: { device_class: :pm25,
131
+ state_class: :measurement } })
132
+ channel.property("pm10-0-atm",
133
+ "PM10",
134
+ :float,
135
+ fields["pm10_0_atm"],
136
+ unit: "µg/m3",
137
+ hass: { sensor: { device_class: :pm10,
138
+ state_class: :measurement } })
139
+ channel.property("p-0-3-um",
140
+ "# particles >= 0.3µm per decileter",
141
+ :float,
142
+ fields["p_0_3_um"],
143
+ hass: { sensor: { state_class: :measurement,
144
+ entity_category: :diagnostic } })
145
+ channel.property("p-0-5-um",
146
+ "# particles >= 0.5µm per decileter",
147
+ :float,
148
+ fields["p_0_5_um"],
149
+ hass: { sensor: { state_class: :measurement,
150
+ entity_category: :diagnostic } })
151
+ channel.property("p-1-0-um",
152
+ "# particles >= 1.0µm per decileter",
153
+ :float,
154
+ fields["p_1_0_um"],
155
+ hass: { sensor: { state_class: :measurement,
156
+ entity_category: :diagnostic } })
157
+ channel.property("p-2-5-um",
158
+ "# particles >= 2.5µm per decileter",
159
+ :float,
160
+ fields["p_2_5_um"],
161
+ hass: { sensor: { state_class: :measurement,
162
+ entity_category: :diagnostic } })
163
+ channel.property("p-5-0-um",
164
+ "# particles >= 5.0µm per decileter",
165
+ :float,
166
+ fields["p_5_0_um"],
167
+ hass: { sensor: { state_class: :measurement,
168
+ entity_category: :diagnostic } })
169
+ channel.property("p-10-0-um",
170
+ "# particles >= 10µm per decileter",
171
+ :float,
172
+ fields["p_10_0_um"],
173
+ hass: { sensor: { state_class: :measurement,
174
+ entity_category: :diagnostic } })
82
175
  end
83
176
 
84
177
  homie.publish
@@ -91,7 +184,7 @@ loop do
91
184
  device["pressure"].value = data["pressure"]
92
185
  device["rssi"].value = data["rssi"]
93
186
 
94
- %w[a b].each do |channel_id|
187
+ CHANNELS.each do |channel_id|
95
188
  fields = get_fields(data, channel_id)
96
189
  channel = homie[channel_id]
97
190
  FIELDS.each do |field|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purpleair
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-13 00:00:00.000000000 Z
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday_middleware
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: homie-mqtt
28
+ name: mqtt-homeassistant
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.4'
33
+ version: '0.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.4'
40
+ version: '0.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: net-http-persistent
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.19'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.12'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.12'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop-rake
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -119,7 +133,8 @@ files:
119
133
  homepage: https://github.com/ccutrer/ruby-purpleair
120
134
  licenses:
121
135
  - MIT
122
- metadata: {}
136
+ metadata:
137
+ rubygems_mfa_required: 'true'
123
138
  post_install_message:
124
139
  rdoc_options: []
125
140
  require_paths: