diff --git a/CHANGELOG.md b/CHANGELOG.md index be94928..dd02a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -174,7 +174,7 @@ ## 3.1.0 * Added support for config-ui-x -* Added custom tresholds for apple home sensors +* Added custom thresholds for apple home sensors ## 3.1.1 * Added unit sitorr for air pressure in mmhg @@ -209,3 +209,8 @@ * Changed precision of rain last hour from 1 mm to 0.1 mm * Fixed city name with optional country code will not be found in OpenWeatherMap * Fixed some missing weather categories for OpenWeatherMap + +## 3.2.1 +* Improved error handling when the service parameter is missing in config +* Fixed spelling of threshold parameter (old variant is still working) +* Fixed crash in WeatherUnderground API when an error occurs diff --git a/README.md b/README.md index 8bccd80..fbbb46e 100644 --- a/README.md +++ b/README.md @@ -210,17 +210,17 @@ Conversions used for reporting values. The default is `"metric"`. The options ar `"ca"` to report wind speeds in km/h `"uk"` to report visibility in miles and wind speeds in miles/h -**tresholdAirPressure** (compatibility `"home"` or `"both"`) -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). +**thresholdAirPressure** (compatibility `"home"` or `"both"`) +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). -**tresholdCloudCover** (compatibility `"home"` or `"both"`) -At what treshold should the cloud cover sensor trigger? Provide a number between 0 (clear) and 100 (overcast). +**thresholdCloudCover** (compatibility `"home"` or `"both"`) +At what threshold should the cloud cover sensor trigger? Provide a number between 0 (clear) and 100 (overcast). -**tresholdUvIndex** (compatibility `"home"` or `"both"`) -At what treshold should the UV-Index sensor trigger? Provide a number >= 0. See https://en.wikipedia.org/wiki/Ultraviolet_index +**thresholdUvIndex** (compatibility `"home"` or `"both"`) +At what threshold should the UV-Index sensor trigger? Provide a number >= 0. See https://en.wikipedia.org/wiki/Ultraviolet_index -**tresholdWindSpeed** (compatibility `"home"` or `"both"`) -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). +**thresholdWindSpeed** (compatibility `"home"` or `"both"`) +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). **fakegatoParameters** 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). diff --git a/apis/weatherunderground.js b/apis/weatherunderground.js index 907a4f3..83b874c 100644 --- a/apis/weatherunderground.js +++ b/apis/weatherunderground.js @@ -49,15 +49,20 @@ class WundergroundAPI try { const jsonObj = JSON.parse(body); - debug(JSON.stringify(jsonObj, null, 2)); - - weather.report = that.parseReport(jsonObj); - callback(null, weather); + if (jsonObj.errors === undefined || jsonObj.errors.length === 0) + { + debug(JSON.stringify(jsonObj, null, 2)); + weather.report = that.parseReport(jsonObj); + callback(null, weather); + } + else + { + throw new Error(JSON.stringify(jsonObj.errors, null, 2)); + } } catch (e) { that.log.error("Error retrieving weather report and forecast"); that.log.error("Error Message: " + e); - that.log.error(body); callback(e); } } @@ -72,7 +77,7 @@ class WundergroundAPI parseReport(json) { - + let that = this; let report = {}; try @@ -114,8 +119,8 @@ class WundergroundAPI } catch (error) { - debug("Error retrieving weather report for Weather Underground"); - debug("Error Message: " + error); + that.log.error("Error parsing weather report for Weather Underground"); + that.log.error("Error Message: " + error); } return report; } diff --git a/index.js b/index.js index 52c5f3a..edd32e2 100644 --- a/index.js +++ b/index.js @@ -51,10 +51,13 @@ function WeatherPlusPlatform(_log, _config) this.stationConfigs = this.config.stations || [this.config]; // Parse config for each station - this.stationConfigs.forEach((station, index) => + this.stationConfigs.forEach((station, index, array) => { station.index = index; - this.parseStationConfig(station); + if (this.parseStationConfig(station) === false) + { + array.splice(index, 1); + } }); // Create accessories @@ -69,7 +72,7 @@ function WeatherPlusPlatform(_log, _config) break; case "weatherunderground": this.log.info("Adding station with weather service Weather Underground named '" + config.nameNow + "'"); - this.stations.push(new weatherunderground(config.key, config.locationId, config.conditionDetail, this.log)); + this.stations.push(new weatherunderground(config.key, config.locationId, this.log)); break; case "openweathermap": this.log.info("Adding station with weather service OpenWeatherMap named '" + config.nameNow + "'"); @@ -120,6 +123,11 @@ WeatherPlusPlatform.prototype = { let stationConfig = JSON.parse(JSON.stringify(station)); // Weather service + if (stationConfig.service === undefined) + { + this.log.error("No weather service configured. Please use config-ui-x or a configuration example from the readme to setup the plugin.") + return false; + } station.service = stationConfig.service.toLowerCase().replace(/\s/g, ""); // Location id. Multiple parameter names are possible for backwards compatiblity @@ -191,6 +199,13 @@ WeatherPlusPlatform.prototype = { array[i] = 7; } }); + + // Compatibility for wrong spelling of threshold + station.thresholdAirPressure = stationConfig.tresholdAirPressure || station.thresholdAirPressure + station.thresholdCloudCover = stationConfig.tresholdCloudCover || station.thresholdCloudCover + station.thresholdUvIndex = stationConfig.tresholdUvIndex || station.thresholdUvIndex + station.thresholdWindSpeed = stationConfig.tresholdWindSpeed || station.thresholdWindSpeed + station.language = stationConfig.language || "en"; station.fakegatoParameters = stationConfig.fakegatoParameters || {storage: "fs"}; station.hidden = stationConfig.hidden || []; @@ -201,6 +216,7 @@ WeatherPlusPlatform.prototype = { } debug(station.hidden); station.serial = station.service + " - " + (station.locationId || '') + (station.locationGeo || '') + (station.locationCity || ''); + return true; }, // Update the weather for all accessories @@ -307,26 +323,26 @@ WeatherPlusPlatform.prototype = { if (name === "AirPressure") { - if (config.tresholdAirPressure === undefined) + if (config.thresholdAirPressure === undefined) { accessory.AirPressureService.setCharacteristic(Characteristic.OccupancyDetected, value >= 1000); } else { - accessory.AirPressureService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.tresholdAirPressure); + accessory.AirPressureService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.thresholdAirPressure); } accessory.AirPressureService.setCharacteristic(Characteristic.Name, "Air Pressure: " + convertedValue + " " + accessory.AirPressureService.unit); accessory.AirPressureService.value = convertedValue; // Save value to use in history } else if (name === "CloudCover") { - if (config.tresholdCloudCover === undefined) + if (config.thresholdCloudCover === undefined) { accessory.CloudCoverService.setCharacteristic(Characteristic.OccupancyDetected, value >= 20); } else { - accessory.CloudCoverService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.tresholdCloudCover); + accessory.CloudCoverService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.thresholdCloudCover); } accessory.CloudCoverService.setCharacteristic(Characteristic.Name, "Cloud Cover: " + convertedValue); } @@ -352,13 +368,13 @@ WeatherPlusPlatform.prototype = { } else if (name === "UVIndex") { - if (config.tresholdUvIndex === undefined) + if (config.thresholdUvIndex === undefined) { accessory.UVIndexService.setCharacteristic(Characteristic.OccupancyDetected, value >= 3); } else { - accessory.UVIndexService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.tresholdUvIndex); + accessory.UVIndexService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.thresholdUvIndex); } accessory.UVIndexService.setCharacteristic(Characteristic.Name, "UV Index: " + convertedValue); } @@ -372,13 +388,13 @@ WeatherPlusPlatform.prototype = { } else if (name === "WindSpeed") { - if (config.tresholdWindSpeed === undefined) + if (config.thresholdWindSpeed === undefined) { accessory.WindSpeedService.setCharacteristic(Characteristic.OccupancyDetected, value >= 5); } else { - accessory.WindSpeedService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.tresholdWindSpeed); + accessory.WindSpeedService.setCharacteristic(Characteristic.OccupancyDetected, convertedValue >= config.thresholdWindSpeed); } accessory.WindSpeedService.setCharacteristic(Characteristic.Name, "Wind Speed: " + convertedValue + " " + accessory.WindSpeedService.unit); } diff --git a/package.json b/package.json index 37f6110..27cd56e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-weather-plus", - "version": "3.2.0", + "version": "3.2.1", "description": "A comprehensive weather plugin for homekit with current observations, forecasts and history.", "license": "MIT", "keywords": [