homebridge-weather
Advanced tools
Comparing version 1.7.0 to 1.7.1
24
index.js
@@ -13,3 +13,3 @@ "use strict"; | ||
Characteristic = homebridge.hap.Characteristic; | ||
FakeGatoHistoryService = require('fakegato-history')(homebridge); | ||
FakeGatoHistoryService = require("fakegato-history")(homebridge); | ||
homebridge.registerAccessory("homebridge-weather", "Weather", WeatherAccessory); | ||
@@ -157,2 +157,3 @@ }; | ||
if (this.cachedWeatherObj) { | ||
var dayNow = new Date().getDay(); | ||
if (this.type === "min") { | ||
@@ -163,2 +164,7 @@ // Unfortunately we cannot use the "16 day weather forecast" API but the "5 day / 3 hour forecast" instead. | ||
for (var i = 0, len = this.cachedWeatherObj["list"].length; i < len; i++) { | ||
var dayThen = new Date(this.cachedWeatherObj["list"][i]["dt"] * 1000).getDay(); | ||
if (dayThen !== dayNow) { | ||
// API returns data for 5 days, we want min/max only for today | ||
break; | ||
} | ||
if (parseFloat(this.cachedWeatherObj["list"][i]["main"]["temp_min"]) < min) { | ||
@@ -171,6 +177,10 @@ min = parseFloat(this.cachedWeatherObj["list"][i]["main"]["temp_min"]); | ||
var max = parseFloat(this.cachedWeatherObj["list"][0]["main"]["temp_max"]); | ||
for (var i = 0, len = this.cachedWeatherObj["list"].length; i < len; i++) { | ||
if (parseFloat(this.cachedWeatherObj["list"][i]["main"]["temp_max"]) > max) { | ||
max = parseFloat(this.cachedWeatherObj["list"][i]["main"]["temp_max"]); | ||
for (var j = 0, len2 = this.cachedWeatherObj["list"].length; j < len2; j++) { | ||
var dayThen2 = new Date(this.cachedWeatherObj["list"][j]["dt"] * 1000).getDay(); | ||
if (dayThen2 !== dayNow) { | ||
break; | ||
} | ||
if (parseFloat(this.cachedWeatherObj["list"][j]["main"]["temp_max"]) > max) { | ||
max = parseFloat(this.cachedWeatherObj["list"][j]["main"]["temp_max"]); | ||
} | ||
} | ||
@@ -198,6 +208,6 @@ temperature = max; | ||
if (this.type === "current") { | ||
url += "weather" | ||
url += "weather"; | ||
} else { | ||
// Min-/Max-sensors have different endpoint | ||
url += "forecast" | ||
url += "forecast"; | ||
} | ||
@@ -290,3 +300,3 @@ | ||
function (error, response, body) { | ||
callback(error, response, body) | ||
callback(error, response, body); | ||
}) | ||
@@ -293,0 +303,0 @@ } |
{ | ||
"name": "homebridge-weather", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "Homebridge plugin for displaying the weather from openweathermap.org", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
20863
301