Skip to content

Commit

Permalink
Several minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
naofireblade committed May 16, 2020
1 parent 49b7e61 commit f9fc5c1
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 29 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
21 changes: 13 additions & 8 deletions apis/weatherunderground.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -72,7 +77,7 @@ class WundergroundAPI

parseReport(json)
{

let that = this;
let report = {};

try
Expand Down Expand Up @@ -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;
}
Expand Down
38 changes: 27 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 + "'");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 || [];
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit f9fc5c1

Please sign in to comment.