add original feels like temperature and fixed it for imperial units

This commit is contained in:
fewieden 2018-12-30 14:17:13 +01:00
parent 88d862303d
commit 8dd7621f29
5 changed files with 44 additions and 17 deletions

View File

@ -48,7 +48,6 @@ The following properties can be configured:
| `lang` | The language of the days. <br><br> **Possible values:** `en`, `nl`, `ru`, etc ... <br> **Default value:** uses value of _config.language_
| `decimalSymbol` | The decimal symbol to use.<br><br> **Possible values:** `.`, `,` or any other symbol.<br> **Default value:** `.`
| `initialLoadDelay` | The initial delay before loading. If you have multiple modules that use the same API key, you might want to delay one of the requests. (Milliseconds) <br><br> **Possible values:** `1000` - `5000` <br> **Default value:** `0`
| `retryDelay` | The delay before retrying after a request failure. (Milliseconds) <br><br> **Possible values:** `1000` - `60000` <br> **Default value:** `2500`
| `appendLocationNameToHeader` | If set to `true`, the returned location name will be appended to the header of the module, if the header is enabled. This is mainly intresting when using calender based weather. <br><br> **Default value:** `true`
| `calendarClass` | The class for the calender module to base the event based weather information on. <br><br> **Default value:** `'calendar'`
@ -63,6 +62,7 @@ The following properties can be configured:
| `showHumidity` | Show the current humidity <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
| `showIndoorTemperature` | If you have another module that emits the `INDOOR_TEMPERATURE` notification, the indoor temperature will be displayed <br> **Default value:** `false`
| `showIndoorHumidity` | If you have another module that emits the `INDOOR_HUMIDITY` notification, the indoor humidity will be displayed <br> **Default value:** `false`
| `showFeelsLike` | Shows the Feels like temperature weather. <br><br> **Possible values:**`true` or `false`<br>**Default value:** `true`
#### Weather forecast options

View File

@ -51,6 +51,13 @@
</span>
{% endif %}
</div>
{% if config.showFeelsLike and not config.onlyTemp %}
<div class="normal medium">
<span class="dimmed">
{{ "FEELS" | translate }} {{ current.feelsLike() | roundValue | unit("temperature") }}
</span>
</div>
{% endif %}
{% else %}
<div class="dimmed light small">
{{"LOADING" | translate}}

View File

@ -17,7 +17,7 @@ WeatherProvider.register("openweathermap", {
providerName: "OpenWeatherMap",
// Overwrite the fetchCurrentWeather method.
fetchCurrentWeather: function() {
fetchCurrentWeather() {
this.fetchData(this.getUrl())
.then(data => {
if (!data || !data.main || typeof data.main.temp === "undefined") {
@ -28,7 +28,7 @@ WeatherProvider.register("openweathermap", {
this.setFetchedLocation(`${data.name}, ${data.sys.country}`);
var currentWeather = this.generateWeatherObjectFromCurrentWeather(data);
const currentWeather = this.generateWeatherObjectFromCurrentWeather(data);
this.setCurrentWeather(currentWeather);
})
.catch(function(request) {
@ -37,7 +37,7 @@ WeatherProvider.register("openweathermap", {
},
// Overwrite the fetchCurrentWeather method.
fetchWeatherForecast: function() {
fetchWeatherForecast() {
this.fetchData(this.getUrl())
.then(data => {
if (!data || !data.list || !data.list.length) {
@ -48,7 +48,7 @@ WeatherProvider.register("openweathermap", {
this.setFetchedLocation(`${data.city.name}, ${data.city.country}`);
var forecast = this.generateWeatherObjectsFromForecast(data.list);
const forecast = this.generateWeatherObjectsFromForecast(data.list);
this.setWeatherForecast(forecast);
})
.catch(function(request) {
@ -62,15 +62,15 @@ WeatherProvider.register("openweathermap", {
/*
* Gets the complete url for the request
*/
getUrl: function() {
getUrl() {
return this.config.apiBase + this.config.apiVersion + this.config.weatherEndpoint + this.getParams();
},
/*
* Generate a WeatherObject based on currentWeatherInformation
*/
generateWeatherObjectFromCurrentWeather: function(currentWeatherData) {
var currentWeather = new WeatherObject();
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
const currentWeather = new WeatherObject(this.config.units);
currentWeather.humidity = currentWeatherData.main.humidity;
currentWeather.temperature = currentWeatherData.main.temp;
@ -86,11 +86,11 @@ WeatherProvider.register("openweathermap", {
/*
* Generate WeatherObjects based on forecast information
*/
generateWeatherObjectsFromForecast: function(forecasts) {
var days = [];
generateWeatherObjectsFromForecast(forecasts) {
const days = [];
for (var forecast of forecasts) {
var weather = new WeatherObject();
for (const forecast of forecasts) {
const weather = new WeatherObject(this.config.units);
weather.date = moment(forecast.dt, "X");
weather.minTemperature = forecast.temp.min;
@ -107,8 +107,8 @@ WeatherProvider.register("openweathermap", {
/*
* Convert the OpenWeatherMap icons to a more usable name.
*/
convertWeatherType: function(weatherType) {
var weatherTypes = {
convertWeatherType(weatherType) {
const weatherTypes = {
"01d": "day-sunny",
"02d": "day-cloudy",
"03d": "cloudy",
@ -137,8 +137,8 @@ WeatherProvider.register("openweathermap", {
*
* return String - URL params.
*/
getParams: function() {
var params = "?";
getParams() {
let params = "?";
if(this.config.locationID) {
params += "id=" + this.config.locationID;
} else if(this.config.location) {

View File

@ -46,7 +46,8 @@ Module.register("weather",{
onlyTemp: false,
showRainAmount: true,
colored: false
colored: false,
showFeelsLike: true
},
// Module properties.

View File

@ -77,4 +77,23 @@ class WeatherObject {
nextSunAction() {
return moment().isBetween(this.sunrise, this.sunset) ? "sunset" : "sunrise";
}
feelsLike() {
const windInMph = this.units === "imperial" ? this.windSpeed : this.windSpeed * 2.23694;
const tempInF = this.units === "imperial" ? this.temperature : this.temperature * 9 / 5 + 32;
let feelsLike = tempInF;
if (windInMph > 3 && tempInF < 50) {
feelsLike = Math.round(35.74 + 0.6215 * tempInF - 35.75 * Math.pow(windInMph, 0.16) + 0.4275 * tempInF * Math.pow(windInMph, 0.16));
} else if (tempInF > 80 && this.humidity > 40) {
feelsLike = -42.379 + 2.04901523 * tempInF + 10.14333127 * this.humidity
- 0.22475541 * tempInF * this.humidity - 6.83783 * Math.pow(10, -3) * tempInF * tempInF
- 5.481717 * Math.pow(10, -2) * this.humidity * this.humidity
+ 1.22874 * Math.pow(10, -3) * tempInF * tempInF * this.humidity
+ 8.5282 * Math.pow(10, -4) * tempInF * this.humidity * this.humidity
- 1.99 * Math.pow(10, -6) * tempInF * tempInF * this.humidity * this.humidity;
}
return this.units === "imperial" ? feelsLike : (feelsLike - 32) * 5 / 9;
}
}