Skip to content

Commit

Permalink
Fixed apparent temperature and dew point not responding if lower than 0C
Browse files Browse the repository at this point in the history
  • Loading branch information
naofireblade committed Dec 27, 2020
1 parent ad25e67 commit 25cc0b9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,6 @@
* Added compatibility sensor for total precipitation
* Changed precision of WeatherUnderground API to decimal
* Fixed crash when OpenWeatherMap API returns no data

## 3.2.3
* Fixed apparent temperature and dew point not responding if lower than 0°C
12 changes: 5 additions & 7 deletions accessories/currentConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ function CurrentConditionsWeatherAccessory(platform, stationIndex)
// Temperature is an official homekit characteristic
if (name === "Temperature")
{
// Fix for negative temperatures, because they are not supported by homekit
this.CurrentConditionsService.getCharacteristic(Characteristic.CurrentTemperature).props.minValue = -50;
// Nothing
}
// Use separate services for these characteristics if compatiblity is "home"
else if (this.config.compatibility === "home" && compatibility.types.includes(name))
Expand Down Expand Up @@ -120,11 +119,10 @@ CurrentConditionsWeatherAccessory.prototype = {
debug("Service: %s", key);
this[key].characteristics.forEach((characteristic) =>
{
if (characteristic.displayName === "Name")
{
debug(" - UUID: %s", characteristic.UUID);
debug(" - Value: %s", characteristic.value);
}
debug(" - Characteristic: %s", characteristic.displayName);
debug(" - UUID: %s", characteristic.UUID);
debug(" - Value: %s", characteristic.value);
debug(" - Props: %s", characteristic.props);
});
}
});
Expand Down
12 changes: 5 additions & 7 deletions accessories/forecast.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ function ForecastWeatherAccessory(platform, stationIndex, day)
// Temperature is an official homekit characteristic
if (name === "TemperatureMax")
{
// Fix for negative temperatures, because they are not supported by homekit
this.ForecastService.getCharacteristic(Characteristic.CurrentTemperature).props.minValue = -50;
// Nothing
}
// Use separate services for these characteristics if compatiblity is "home"
else if (this.config.compatibility === "home" && compatibility.types.includes(name))
Expand Down Expand Up @@ -123,11 +122,10 @@ ForecastWeatherAccessory.prototype = {
debug("Service: %s", key);
this[key].characteristics.forEach((characteristic) =>
{
if (characteristic.displayName === "Name")
{
debug(" - UUID: %s", characteristic.UUID);
debug(" - Value: %s", characteristic.value);
}
debug(" - Characteristic: %s", characteristic.displayName);
debug(" - UUID: %s", characteristic.UUID);
debug(" - Value: %s", characteristic.value);
debug(" - Props: %s", characteristic.props);
});
}
});
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.2",
"version": "3.2.3",
"description": "A comprehensive weather plugin for homekit with current observations, forecasts and history.",
"license": "MIT",
"keywords": [
Expand Down
32 changes: 16 additions & 16 deletions util/characteristics.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ function round(value, decimals)
module.exports = function (Characteristic, units)
{

units = // rainfail temperature visibility windspeed airpressure
units = // rainfail temperature visibility windspeed airpressure
{
ca: 'ca' // mm celsius kilometers km/hour hPa
, imperial: 'imperial' // inches fahrenheit miles miles/hour hPa
, si: 'si' // mm celsius kilometers m/second hPa
, sitorr: 'sitorr' // mm celsius kilometers m/second mmhg
, uk: 'uk' // mm celsius miles miles/hour hPa

, metric: 'si'
, us: 'imperial'
ca: 'ca', // mm celsius kilometers km/hour hPa
imperial: 'imperial',
us: 'imperial', // inches fahrenheit miles miles/hour hPa
si: 'si',
metric: 'si', // mm celsius kilometers m/second hPa
sitorr: 'sitorr', // mm celsius kilometers m/second mmhg
uk: 'uk' // mm celsius miles miles/hour hPa

}[units.toLowerCase()];
if (!units) units = 'si';

Expand All @@ -78,15 +78,15 @@ module.exports = function (Characteristic, units)
{
return (celsius * 1.8) + 32;
};
var temperatureProps = (max, min) =>
var temperatureProps = (min, max) =>
{
var range = (units !== 'imperial') ? {unit: Characteristic.Units.CELSIUS, maxValue: max, minValue: min}
: {unit: 'fahrenheit', maxValue: c2f(max), minValue: c2f(min)};

return underscore.extend(
{
format: Characteristic.Formats.UINT8
, minStep: 1
format: Characteristic.Formats.FLOAT
, minStep: 0.1
, perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
}, range);
};
Expand Down Expand Up @@ -213,11 +213,11 @@ module.exports = function (Characteristic, units)
CustomCharacteristic.DewPoint = function ()
{
Characteristic.call(this, 'Dew Point', CustomUUID.DewPoint);
this.setProps(temperatureProps(50, -50));
this.setProps(temperatureProps(-50, 100));
this.value = this.getDefaultValue();
};
inherits(CustomCharacteristic.DewPoint, Characteristic);
// Homekit converts temperature by itself accoding to the user device settings
// Homekit converts temperature by itself according to the user device settings

CustomCharacteristic.ForecastDay = function ()
{
Expand Down Expand Up @@ -369,7 +369,7 @@ module.exports = function (Characteristic, units)
CustomCharacteristic.TemperatureMin = function ()
{
Characteristic.call(this, 'Temperature Min', CustomUUID.TemperatureMin);
this.setProps(temperatureProps(50, -50));
this.setProps(temperatureProps(-50, 100));
this.value = this.getDefaultValue();
};
inherits(CustomCharacteristic.TemperatureMin, Characteristic);
Expand All @@ -378,7 +378,7 @@ module.exports = function (Characteristic, units)
CustomCharacteristic.TemperatureApparent = function ()
{
Characteristic.call(this, 'Apparent temperature', CustomUUID.TemperatureApparent);
this.setProps(temperatureProps(50, -50));
this.setProps(temperatureProps(-50, 100));
this.value = this.getDefaultValue();
};
inherits(CustomCharacteristic.TemperatureApparent, Characteristic);
Expand Down

0 comments on commit 25cc0b9

Please sign in to comment.