Skip to content

Commit f9fc5c1

Browse files
committed
Several minor bug fixes
1 parent 49b7e61 commit f9fc5c1

File tree

5 files changed

+55
-29
lines changed

5 files changed

+55
-29
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174

175175
## 3.1.0
176176
* Added support for config-ui-x
177-
* Added custom tresholds for apple home sensors
177+
* Added custom thresholds for apple home sensors
178178

179179
## 3.1.1
180180
* Added unit sitorr for air pressure in mmhg
@@ -209,3 +209,8 @@
209209
* Changed precision of rain last hour from 1 mm to 0.1 mm
210210
* Fixed city name with optional country code will not be found in OpenWeatherMap
211211
* Fixed some missing weather categories for OpenWeatherMap
212+
213+
## 3.2.1
214+
* Improved error handling when the service parameter is missing in config
215+
* Fixed spelling of threshold parameter (old variant is still working)
216+
* Fixed crash in WeatherUnderground API when an error occurs

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,17 @@ Conversions used for reporting values. The default is `"metric"`. The options ar
210210
`"ca"` to report wind speeds in km/h
211211
`"uk"` to report visibility in miles and wind speeds in miles/h
212212

213-
**tresholdAirPressure** (compatibility `"home"` or `"both"`)
214-
At what treshold should the air pressure sensor trigger? Provide a number without unit. The range depends on your unit setting (sitorr -> mmhg, otherwise -> hPa).
213+
**thresholdAirPressure** (compatibility `"home"` or `"both"`)
214+
At what threshold should the air pressure sensor trigger? Provide a number without unit. The range depends on your unit setting (sitorr -> mmhg, otherwise -> hPa).
215215

216-
**tresholdCloudCover** (compatibility `"home"` or `"both"`)
217-
At what treshold should the cloud cover sensor trigger? Provide a number between 0 (clear) and 100 (overcast).
216+
**thresholdCloudCover** (compatibility `"home"` or `"both"`)
217+
At what threshold should the cloud cover sensor trigger? Provide a number between 0 (clear) and 100 (overcast).
218218

219-
**tresholdUvIndex** (compatibility `"home"` or `"both"`)
220-
At what treshold should the UV-Index sensor trigger? Provide a number >= 0. See https://en.wikipedia.org/wiki/Ultraviolet_index
219+
**thresholdUvIndex** (compatibility `"home"` or `"both"`)
220+
At what threshold should the UV-Index sensor trigger? Provide a number >= 0. See https://en.wikipedia.org/wiki/Ultraviolet_index
221221

222-
**tresholdWindSpeed** (compatibility `"home"` or `"both"`)
223-
At what treshold should the wind speed sensor trigger? Provide a number without unit. The range depends on your unit setting (si/metric/sitorr -> m/s, ca -> km/h, uk/us/imperial -> miles/h).
222+
**thresholdWindSpeed** (compatibility `"home"` or `"both"`)
223+
At what threshold should the wind speed sensor trigger? Provide a number without unit. The range depends on your unit setting (si/metric/sitorr -> m/s, ca -> km/h, uk/us/imperial -> miles/h).
224224

225225
**fakegatoParameters**
226226
Customization of the history storage system. By default, the history is persisted on the filesystem. You can set your own option using this parameter. In order to change the [location of the persisted file](https://github.com/simont77/fakegato-history#file-system) or to use [GoogleDrive](https://github.com/simont77/fakegato-history#google-drive).

apis/weatherunderground.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ class WundergroundAPI
4949
try
5050
{
5151
const jsonObj = JSON.parse(body);
52-
debug(JSON.stringify(jsonObj, null, 2));
53-
54-
weather.report = that.parseReport(jsonObj);
55-
callback(null, weather);
52+
if (jsonObj.errors === undefined || jsonObj.errors.length === 0)
53+
{
54+
debug(JSON.stringify(jsonObj, null, 2));
55+
weather.report = that.parseReport(jsonObj);
56+
callback(null, weather);
57+
}
58+
else
59+
{
60+
throw new Error(JSON.stringify(jsonObj.errors, null, 2));
61+
}
5662
} catch (e)
5763
{
5864
that.log.error("Error retrieving weather report and forecast");
5965
that.log.error("Error Message: " + e);
60-
that.log.error(body);
6166
callback(e);
6267
}
6368
}
@@ -72,7 +77,7 @@ class WundergroundAPI
7277

7378
parseReport(json)
7479
{
75-
80+
let that = this;
7681
let report = {};
7782

7883
try
@@ -114,8 +119,8 @@ class WundergroundAPI
114119

115120
} catch (error)
116121
{
117-
debug("Error retrieving weather report for Weather Underground");
118-
debug("Error Message: " + error);
122+
that.log.error("Error parsing weather report for Weather Underground");
123+
that.log.error("Error Message: " + error);
119124
}
120125
return report;
121126
}

index.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ function WeatherPlusPlatform(_log, _config)
5151
this.stationConfigs = this.config.stations || [this.config];
5252

5353
// Parse config for each station
54-
this.stationConfigs.forEach((station, index) =>
54+
this.stationConfigs.forEach((station, index, array) =>
5555
{
5656
station.index = index;
57-
this.parseStationConfig(station);
57+
if (this.parseStationConfig(station) === false)
58+
{
59+
array.splice(index, 1);
60+
}
5861
});
5962

6063
// Create accessories
@@ -69,7 +72,7 @@ function WeatherPlusPlatform(_log, _config)
6972
break;
7073
case "weatherunderground":
7174
this.log.info("Adding station with weather service Weather Underground named '" + config.nameNow + "'");
72-
this.stations.push(new weatherunderground(config.key, config.locationId, config.conditionDetail, this.log));
75+
this.stations.push(new weatherunderground(config.key, config.locationId, this.log));
7376
break;
7477
case "openweathermap":
7578
this.log.info("Adding station with weather service OpenWeatherMap named '" + config.nameNow + "'");
@@ -120,6 +123,11 @@ WeatherPlusPlatform.prototype = {
120123
let stationConfig = JSON.parse(JSON.stringify(station));
121124

122125
// Weather service
126+
if (stationConfig.service === undefined)
127+
{
128+
this.log.error("No weather service configured. Please use config-ui-x or a configuration example from the readme to setup the plugin.")
129+
return false;
130+
}
123131
station.service = stationConfig.service.toLowerCase().replace(/\s/g, "");
124132

125133
// Location id. Multiple parameter names are possible for backwards compatiblity
@@ -191,6 +199,13 @@ WeatherPlusPlatform.prototype = {
191199
array[i] = 7;
192200
}
193201
});
202+
203+
// Compatibility for wrong spelling of threshold
204+
station.thresholdAirPressure = stationConfig.tresholdAirPressure || station.thresholdAirPressure
205+
station.thresholdCloudCover = stationConfig.tresholdCloudCover || station.thresholdCloudCover
206+
station.thresholdUvIndex = stationConfig.tresholdUvIndex || station.thresholdUvIndex
207+
station.thresholdWindSpeed = stationConfig.tresholdWindSpeed || station.thresholdWindSpeed
208+
194209
station.language = stationConfig.language || "en";
195210
station.fakegatoParameters = stationConfig.fakegatoParameters || {storage: "fs"};
196211
station.hidden = stationConfig.hidden || [];
@@ -201,6 +216,7 @@ WeatherPlusPlatform.prototype = {
201216
}
202217
debug(station.hidden);
203218
station.serial = station.service + " - " + (station.locationId || '') + (station.locationGeo || '') + (station.locationCity || '');
219+
return true;
204220
},
205221

206222
// Update the weather for all accessories
@@ -307,26 +323,26 @@ WeatherPlusPlatform.prototype = {
307323

308324
if (name === "AirPressure")
309325
{
310-
if (config.tresholdAirPressure === undefined)
326+
if (config.thresholdAirPressure === undefined)
311327
{
312328
accessory.AirPressureService.setCharacteristic(Characteristic.OccupancyDetected, value >= 1000);
313329
}
314330
else
315331
{
316-
accessory.AirPressureService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.tresholdAirPressure);
332+
accessory.AirPressureService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.thresholdAirPressure);
317333
}
318334
accessory.AirPressureService.setCharacteristic(Characteristic.Name, "Air Pressure: " + convertedValue + " " + accessory.AirPressureService.unit);
319335
accessory.AirPressureService.value = convertedValue; // Save value to use in history
320336
}
321337
else if (name === "CloudCover")
322338
{
323-
if (config.tresholdCloudCover === undefined)
339+
if (config.thresholdCloudCover === undefined)
324340
{
325341
accessory.CloudCoverService.setCharacteristic(Characteristic.OccupancyDetected, value >= 20);
326342
}
327343
else
328344
{
329-
accessory.CloudCoverService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.tresholdCloudCover);
345+
accessory.CloudCoverService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.thresholdCloudCover);
330346
}
331347
accessory.CloudCoverService.setCharacteristic(Characteristic.Name, "Cloud Cover: " + convertedValue);
332348
}
@@ -352,13 +368,13 @@ WeatherPlusPlatform.prototype = {
352368
}
353369
else if (name === "UVIndex")
354370
{
355-
if (config.tresholdUvIndex === undefined)
371+
if (config.thresholdUvIndex === undefined)
356372
{
357373
accessory.UVIndexService.setCharacteristic(Characteristic.OccupancyDetected, value >= 3);
358374
}
359375
else
360376
{
361-
accessory.UVIndexService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.tresholdUvIndex);
377+
accessory.UVIndexService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.thresholdUvIndex);
362378
}
363379
accessory.UVIndexService.setCharacteristic(Characteristic.Name, "UV Index: " + convertedValue);
364380
}
@@ -372,13 +388,13 @@ WeatherPlusPlatform.prototype = {
372388
}
373389
else if (name === "WindSpeed")
374390
{
375-
if (config.tresholdWindSpeed === undefined)
391+
if (config.thresholdWindSpeed === undefined)
376392
{
377393
accessory.WindSpeedService.setCharacteristic(Characteristic.OccupancyDetected, value >= 5);
378394
}
379395
else
380396
{
381-
accessory.WindSpeedService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.tresholdWindSpeed);
397+
accessory.WindSpeedService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.thresholdWindSpeed);
382398
}
383399
accessory.WindSpeedService.setCharacteristic(Characteristic.Name, "Wind Speed: " + convertedValue + " " + accessory.WindSpeedService.unit);
384400
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "homebridge-weather-plus",
3-
"version": "3.2.0",
3+
"version": "3.2.1",
44
"description": "A comprehensive weather plugin for homekit with current observations, forecasts and history.",
55
"license": "MIT",
66
"keywords": [

0 commit comments

Comments
 (0)