Skip to content

Commit

Permalink
Fixed temperature not responding if lower than 0°C since v3.2.3
Browse files Browse the repository at this point in the history
Fixed apparent temperature and dew point not responding in compatibility mode home if lower than 0°C
Fixed apparent temperature and dew point are not converted to F in compatibility mode eve
Fixed startup error when using compatibility mode eve2 (eve with grouping) and forecasts
  • Loading branch information
naofireblade committed Dec 28, 2020
1 parent 25cc0b9 commit 52117dd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,10 @@
* Fixed crash when OpenWeatherMap API returns no data

## 3.2.3
* Fixed apparent temperature and dew point not responding if lower than 0°C
* Fixed apparent temperature and dew point not responding if lower than 0°C

## 3.2.4
* Fixed temperature not responding if lower than 0°C since v3.2.3
* Fixed apparent temperature and dew point not responding in compatibility mode home if lower than 0°C
* Fixed apparent temperature and dew point are not converted to F in compatibility mode eve
* Fixed startup error when using compatibility mode eve2 (eve with grouping) and forecasts
7 changes: 4 additions & 3 deletions accessories/currentConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ function CurrentConditionsWeatherAccessory(platform, stationIndex)
// Temperature is an official homekit characteristic
if (name === "Temperature")
{
// Nothing
// Fix for negative temperatures, because they are not supported by homekit
this.CurrentConditionsService.getCharacteristic(Characteristic.CurrentTemperature).props.minValue = -50;
}
// Use separate services for these characteristics if compatiblity is "home"
else if (this.config.compatibility === "home" && compatibility.types.includes(name))
{
compatibility.createService(this, name, Service, CustomCharacteristic);
compatibility.createService(this, name, Service, Characteristic, CustomCharacteristic);
}
// Use separate services and the temperature service for these characteristics if compatiblity is "both"
else if (this.config.compatibility === "both" && compatibility.types.includes(name))
{
compatibility.createService(this, name, Service, CustomCharacteristic);
compatibility.createService(this, name, Service, Characteristic, CustomCharacteristic);
if (name === "Humidity")
{
this.CurrentConditionsService.addCharacteristic(Characteristic.CurrentRelativeHumidity);
Expand Down
11 changes: 7 additions & 4 deletions accessories/forecast.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ const debug = require('debug')('homebridge-weather-plus'),

let Service,
Characteristic,
CustomService,
CustomCharacteristic;

module.exports = function (_Service, _Characteristic, _CustomCharacteristic)
module.exports = function (_Service, _Characteristic, _CustomService, _CustomCharacteristic)
{
Service = _Service;
Characteristic = _Characteristic;
CustomService = _CustomService;
CustomCharacteristic = _CustomCharacteristic;

return ForecastWeatherAccessory;
Expand Down Expand Up @@ -70,17 +72,18 @@ function ForecastWeatherAccessory(platform, stationIndex, day)
// Temperature is an official homekit characteristic
if (name === "TemperatureMax")
{
// Nothing
// Fix for negative temperatures, because they are not supported by homekit
this.ForecastService.getCharacteristic(Characteristic.CurrentTemperature).props.minValue = -50;
}
// Use separate services for these characteristics if compatiblity is "home"
else if (this.config.compatibility === "home" && compatibility.types.includes(name))
{
compatibility.createService(this, name, Service, CustomCharacteristic);
compatibility.createService(this, name, Service, Characteristic, CustomCharacteristic);
}
// Use separate services and the temperature service for these characteristics if compatiblity is "both"
else if (this.config.compatibility === "both" && compatibility.types.includes(name))
{
compatibility.createService(this, name, Service, CustomCharacteristic);
compatibility.createService(this, name, Service, Characteristic, CustomCharacteristic);
if (name === "Humidity")
{
this.ForecastService.addCharacteristic(Characteristic.CurrentRelativeHumidity);
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function WeatherPlusPlatform(_log, _config)
CustomService = require("./util/services")(Service, Characteristic);
CustomCharacteristic = require("./util/characteristics")(Characteristic, this.units);
CurrentConditionsWeatherAccessory = require("./accessories/currentConditions")(Service, Characteristic, CustomService, CustomCharacteristic, FakeGatoHistoryService);
ForecastWeatherAccessory = require("./accessories/forecast")(Service, Characteristic, CustomCharacteristic);
ForecastWeatherAccessory = require("./accessories/forecast")(Service, Characteristic, CustomService, CustomCharacteristic);

// Create weather stations, create default one if no stations array given
this.stationConfigs = this.config.stations || [this.config];
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.3",
"version": "3.2.4",
"description": "A comprehensive weather plugin for homekit with current observations, forecasts and history.",
"license": "MIT",
"keywords": [
Expand Down
37 changes: 21 additions & 16 deletions util/characteristics.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = function (Characteristic, units)
}[units.toLowerCase()];
if (!units) units = 'si';

var rainfallProps = (max) =>
let rainfallProps = (max) =>
{
var range = (units !== 'imperial') ? {unit: 'mm', maxValue: max, minValue: 0, minStep: 0.1}
: {unit: 'in', maxValue: Math.round(max / 25.4), minValue: 0, minStep: 0.01};
Expand All @@ -69,19 +69,20 @@ module.exports = function (Characteristic, units)
, perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
}, range);
};
var rainfallValue = (val) =>
let rainfallValue = (val) =>
{
return (units !== 'imperial') ? val : round(val / 25.4, 2);
};

var c2f = (celsius) =>
let temperatureValue = (celsius) =>
{
return (celsius * 1.8) + 32;
return units === 'imperial' ? (round(celsius * 1.8, 1)) + 32 : celsius;
};
var temperatureProps = (min, max) =>
let temperatureProps = (min, max) =>
{
var range = (units !== 'imperial') ? {unit: Characteristic.Units.CELSIUS, maxValue: max, minValue: min}
: {unit: 'fahrenheit', maxValue: c2f(max), minValue: c2f(min)};
var range = {unit: units === 'imperial' ? 'fahrenheit' : Characteristic.Units.CELSIUS,
minValue: temperatureValue(min),
maxValue: temperatureValue(max)};

return underscore.extend(
{
Expand All @@ -91,11 +92,11 @@ module.exports = function (Characteristic, units)
}, range);
};

var km2mi = (km) =>
let km2mi = (km) =>
{
return Math.round(km / 1.60934);
};
var visibilityProps = (max) =>
let visibilityProps = (max) =>
{
var range = ((units === 'si') || (units === 'sitorr') || (units === 'ca')) ? {unit: 'km', maxValue: max, minValue: 0}
: {unit: 'mi', maxValue: km2mi(max), minValue: 0};
Expand All @@ -107,20 +108,20 @@ module.exports = function (Characteristic, units)
, perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
}, range);
};
var visibilityValue = (val) =>
let visibilityValue = (val) =>
{
return ((units === 'si') || (units === 'sitorr') || (units === 'ca')) ? val : km2mi(val);
};

var mtos2kmh = (m) =>
let mtos2kmh = (m) =>
{
return (round((m * 3600) / 1000, 2));
};
var mtos2mih = (m) =>
let mtos2mih = (m) =>
{
return (round((m * 3600) / 1609.34, 2));
};
var windspeedProps = (max) =>
let windspeedProps = (max) =>
{
var range = ((units === 'si') || (units === 'sitorr')) ? {unit: 'm/s', maxValue: max, minValue: 0}
: (units === 'ca') ? {unit: 'km/h', maxValue: mtos2kmh(max), minValue: 0}
Expand All @@ -133,7 +134,7 @@ module.exports = function (Characteristic, units)
, perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
}, range);
};
var windspeedValue = (val) =>
let windspeedValue = (val) =>
{
return ((units === 'si') || (units === 'sitorr')) ? val
: (units === 'ca') ? mtos2kmh(val)
Expand Down Expand Up @@ -217,7 +218,8 @@ module.exports = function (Characteristic, units)
this.value = this.getDefaultValue();
};
inherits(CustomCharacteristic.DewPoint, Characteristic);
// Homekit converts temperature by itself according to the user device settings
// Custom temperature characteristics must be converted manually
CustomCharacteristic.DewPoint._unitvalue = temperatureValue;

CustomCharacteristic.ForecastDay = function ()
{
Expand Down Expand Up @@ -373,7 +375,8 @@ module.exports = function (Characteristic, units)
this.value = this.getDefaultValue();
};
inherits(CustomCharacteristic.TemperatureMin, Characteristic);
// Homekit converts temperature by itself accoding to the user device settings
// Custom temperature characteristics must be converted manually
CustomCharacteristic.TemperatureMin._unitvalue = temperatureValue;

CustomCharacteristic.TemperatureApparent = function ()
{
Expand All @@ -382,6 +385,8 @@ module.exports = function (Characteristic, units)
this.value = this.getDefaultValue();
};
inherits(CustomCharacteristic.TemperatureApparent, Characteristic);
// Custom temperature characteristics must be converted manually
CustomCharacteristic.TemperatureApparent._unitvalue = temperatureValue;

CustomCharacteristic.UVIndex = function ()
{
Expand Down
5 changes: 4 additions & 1 deletion util/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const types = ["AirPressure", "CloudCover", "DewPoint", "Humidity", "RainBool", "SnowBool", "TemperatureMin", "TemperatureApparent", "UVIndex", "Visibility", "WindDirection", "WindSpeed", "RainDay"];

const createService = function (that, name, Service, CustomCharacteristic)
const createService = function (that, name, Service, Characteristic, CustomCharacteristic)
{
if (name === "AirPressure")
{
Expand All @@ -21,6 +21,7 @@ const createService = function (that, name, Service, CustomCharacteristic)
if (name === "DewPoint")
{
that.DewPointService = new Service.TemperatureSensor("Dew Point", "Dew Point");
that.DewPointService.getCharacteristic(Characteristic.CurrentTemperature).props.minValue = -50;
}
if (name === "Humidity")
{
Expand All @@ -37,10 +38,12 @@ const createService = function (that, name, Service, CustomCharacteristic)
if (name === "TemperatureMin")
{
that.TemperatureMinService = new Service.TemperatureSensor("Minimum Temperature", "TemperatureMin");
that.TemperatureMinService.getCharacteristic(Characteristic.CurrentTemperature).props.minValue = -50;
}
if (name === "TemperatureApparent")
{
that.TemperatureApparentService = new Service.TemperatureSensor("Apparent Temperature", "TemperatureApparent");
that.TemperatureApparentService.getCharacteristic(Characteristic.CurrentTemperature).props.minValue = -50;
}
if (name === "UVIndex")
{
Expand Down

0 comments on commit 52117dd

Please sign in to comment.