lita-onewheel-aqi 2.0.9 → 2.0.10
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 +4 -4
- data/lib/lita/handlers/onewheel_aqi.rb +30 -15
- data/lita-onewheel-aqi.gemspec +1 -1
- data/spec/lita/handlers/onewheel_aqi_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d04773171d0c0dd5ae10537abfe5d3131a25d54
|
4
|
+
data.tar.gz: 39d74cd311c6c2fbf1c3bc8870849f7fa793c08d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514b49d9f19dfa4ef1b2321b9f1b207bf9228717bba124d666d6e00532e71192687908e527b32ce74ed5c7093c7596623d72ca05e4b58f6c0b5bce85d1526703
|
7
|
+
data.tar.gz: da51c6ec10fb801c5c7c2b69955f81f4d393bc4864ab42c48be64359134647129229f8c78f915781ca91f6f577ad93d654d16615467e3f4a3fbae142980456ba
|
@@ -82,7 +82,7 @@ module Lita
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def get_location(response)
|
85
|
-
location = if response.matches[0].to_s.
|
85
|
+
location = if response.matches[0][0].to_s.length == 1
|
86
86
|
''
|
87
87
|
else
|
88
88
|
response.matches[0][0]
|
@@ -125,6 +125,8 @@ module Lita
|
|
125
125
|
|
126
126
|
if aqi['data']['iaqi']['pm25']
|
127
127
|
reply += 'pm25: ' + color_str(aqi['data']['iaqi']['pm25']['v'].to_s) + ' '
|
128
|
+
ugm3 = pm25_to_ugm3 aqi['data']['iaqi']['pm25']['v'].to_s
|
129
|
+
reply += "#{ugm3} µgm3(est) "
|
128
130
|
end
|
129
131
|
if aqi['data']['iaqi']['pm10']
|
130
132
|
reply += 'pm10: ' + color_str(aqi['data']['iaqi']['pm10']['v'].to_s) + ' '
|
@@ -160,11 +162,13 @@ module Lita
|
|
160
162
|
if aqi['data']['iaqi']['p']
|
161
163
|
reply += 'pressure: ' + aqi['data']['iaqi']['p']['v'].to_s + 'mb '
|
162
164
|
end
|
163
|
-
if aqi['data']['iaqi']['pm10']
|
164
|
-
reply += 'pm10: ' + color_str(aqi['data']['iaqi']['pm10']['v'].to_s) + ' '
|
165
|
-
end
|
166
165
|
if aqi['data']['iaqi']['pm25']
|
167
166
|
reply += 'pm25: ' + color_str(aqi['data']['iaqi']['pm25']['v'].to_s) + ' '
|
167
|
+
ugm3 = pm25_to_ugm3 aqi['data']['iaqi']['pm25']['v']
|
168
|
+
reply += "#{ugm3} µgm3(est) "
|
169
|
+
end
|
170
|
+
if aqi['data']['iaqi']['pm10']
|
171
|
+
reply += 'pm10: ' + color_str(aqi['data']['iaqi']['pm10']['v'].to_s) + ' '
|
168
172
|
end
|
169
173
|
if aqi['data']['iaqi']['t']
|
170
174
|
reply += 'temp: ' + aqi['data']['iaqi']['t']['v'].to_s + 'C '
|
@@ -206,17 +210,6 @@ module Lita
|
|
206
210
|
str
|
207
211
|
end
|
208
212
|
|
209
|
-
def extract_pmtwofive(aqi)
|
210
|
-
Lita.logger.debug "extract_pmtwofive with #{aqi}"
|
211
|
-
pm25 = ''
|
212
|
-
pm25 = if aqi['data']['iaqi']['pm25']
|
213
|
-
aqi['data']['iaqi']['pm25']['v']
|
214
|
-
else
|
215
|
-
"No PM2.5 data for #{aqi['data']['city']['name']}"
|
216
|
-
end
|
217
|
-
pm25
|
218
|
-
end
|
219
|
-
|
220
213
|
# Geographical stuffs
|
221
214
|
# Now with less caching!
|
222
215
|
def optimistic_geo_wrapper(query)
|
@@ -237,6 +230,28 @@ module Lita
|
|
237
230
|
lat: geocoded['geometry']['location']['lat'],
|
238
231
|
lng: geocoded['geometry']['location']['lng'] }
|
239
232
|
end
|
233
|
+
|
234
|
+
# Particulate Matter 2.5 to micrograms per cubic meter
|
235
|
+
def pm25_to_ugm3(pm25)
|
236
|
+
ranges = {
|
237
|
+
0..50 => [0, 50, 0.0, 12.0],
|
238
|
+
51..100 => [51, 100, 12.1, 35.4],
|
239
|
+
101..150 => [101, 150, 35.5, 55.4],
|
240
|
+
151..200 => [151, 200, 55.5, 150.4],
|
241
|
+
201..300 => [201, 300, 150.5, 250.4],
|
242
|
+
301..500 => [301, 500, 250.5, 500]
|
243
|
+
}
|
244
|
+
ranges.keys.each do |range_key|
|
245
|
+
next unless range_key.cover? pm25.to_i
|
246
|
+
low = ranges[range_key][0]
|
247
|
+
high = ranges[range_key][1]
|
248
|
+
min = ranges[range_key][2]
|
249
|
+
max = ranges[range_key][3]
|
250
|
+
step = (max - min) / (high - low)
|
251
|
+
ugm3 = (pm25.to_i - low) * step + min
|
252
|
+
return ugm3.round(2)
|
253
|
+
end
|
254
|
+
end
|
240
255
|
end
|
241
256
|
|
242
257
|
Lita.register_handler(OnewheelAqi)
|
data/lita-onewheel-aqi.gemspec
CHANGED
@@ -34,11 +34,11 @@ describe Lita::Handlers::OnewheelAqi, lita_handler: true do
|
|
34
34
|
|
35
35
|
it 'queries the aqi' do
|
36
36
|
send_command 'aqi'
|
37
|
-
expect(replies.last).to include("AQI for Portland, OR, USA, ⚠️ 08Moderate ⚠️ pm25: 0876 pm10: 0340 updated 0860 minutes ago. 14(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)")
|
37
|
+
expect(replies.last).to include("AQI for Portland, OR, USA, ⚠️ 08Moderate ⚠️ pm25: 0876 23.99 µgm3(est) pm10: 0340 updated 0860 minutes ago. 14(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)")
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'queries the aqideets' do
|
41
41
|
send_command 'aqideets'
|
42
|
-
expect(replies.last).to eq("AQI for Portland, OR, USA, ⚠️ 08Moderate ⚠️ humidity: 11% pressure: 1014mb
|
42
|
+
expect(replies.last).to eq("AQI for Portland, OR, USA, ⚠️ 08Moderate ⚠️ humidity: 11% pressure: 1014mb pm25: 0876 23.99 µgm3(est) pm10: 0340 temp: 34.65C updated 0860 minutes ago. 14(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)")
|
43
43
|
end
|
44
44
|
end
|