homebridge-weather
Advanced tools
Comparing version 1.0.0 to 1.1.1
23
index.js
@@ -17,3 +17,6 @@ "use strict"; | ||
this.apikey = config["apikey"]; | ||
this.location = config["location"]; | ||
this.locationByCity = config["location"]; | ||
this.locationById = config["locationById"]; | ||
this.locationByCoordinates = config["locationByCoordinates"]; | ||
this.locationByZip = config["locationByZip"]; | ||
this.lastupdate = 0; | ||
@@ -28,3 +31,13 @@ this.temperature = 0; | ||
if (this.lastupdate + (60 * 60) < (Date.now() / 1000 | 0)) { | ||
var url = "http://api.openweathermap.org/data/2.5/weather?q=" + this.location + "&APPID=" + this.apikey; | ||
var url = "http://api.openweathermap.org/data/2.5/weather?APPID=" + this.apikey + "&"; | ||
if (this.locationByCity) { | ||
url += "q=" + this.locationByCity; | ||
} else if (this.locationById) { | ||
url += "id=" + this.locationById; | ||
} else if (this.locationByCoordinates) { | ||
url += this.locationByCoordinates; | ||
} else if (this.locationByZip) { | ||
url += "zip=" + this.locationByZip; | ||
} | ||
this.httpRequest(url, function (error, response, responseBody) { | ||
@@ -52,4 +65,4 @@ if (error) { | ||
identify: function (callback) { | ||
this.log("Identify requested!"); | ||
callback(); // success | ||
this.log("Identify requested"); | ||
callback(); | ||
}, | ||
@@ -63,3 +76,3 @@ | ||
.setCharacteristic(Characteristic.Model, "Location") | ||
.setCharacteristic(Characteristic.SerialNumber, ""); | ||
.setCharacteristic(Characteristic.SerialNumber, "XDWS13"); | ||
@@ -66,0 +79,0 @@ temperatureService = new Service.TemperatureSensor(this.name); |
{ | ||
"name": "homebridge-weather", | ||
"version": "1.0.0", | ||
"version": "1.1.1", | ||
"description": "A homebridge temperature sensor for displaying the weather at your current location.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ # homebridge-weather | ||
3. Get an API-Key from <a href="http://openweathermap.org">openweathermap.org</a> | ||
4. <a href="https://openweathermap.org/city">Find</a> your city (make sure the query only returns a single result). | ||
4. <a href="https://openweathermap.org/city">Find</a> your city (make sure the query only returns a single result). Alternatively you can use a different query parameter (see 'Fields') | ||
5. Update your Homebridge `config.json` using the sample below. | ||
@@ -16,2 +16,4 @@ | ||
## By City | ||
```json | ||
@@ -26,2 +28,24 @@ { | ||
## By ID | ||
```json | ||
{ | ||
"accessory": "Weather", | ||
"apikey": "YOUR_KEY_HERE", | ||
"locationById": "2172797", | ||
"name": "OpenWeatherMap Temperature" | ||
} | ||
``` | ||
## By Coordinates | ||
```json | ||
{ | ||
"accessory": "Weather", | ||
"apikey": "YOUR_KEY_HERE", | ||
"locationByCoordinates": "lat=35&lon=139", | ||
"name": "OpenWeatherMap Temperature" | ||
} | ||
``` | ||
Fields: | ||
@@ -31,4 +55,7 @@ | ||
* `apikey` API-Key for accessing OpenWeatherMap API (required). | ||
* `location` location query string (resembles to <a href="https://openweathermap.org/current#name">q-parameter</a>) (required). | ||
* `location` city-name query string (resembles to <a href="https://openweathermap.org/current#name">q-parameter</a>) (required). | ||
* OR `locationById` cityid query string (resembles to <a href="https://openweathermap.org/current#cityid">cityid-parameter</a>) (required). | ||
* OR `locationByCoordinates` geo query string (resembles to <a href="https://openweathermap.org/current#geo">geo-parameter</a>) (required). | ||
* OR `locationByZip` zip query string (resembles to <a href="https://openweathermap.org/current#zip">zip-parameter</a>) (required). | ||
* `name` is the name of the published accessory (required). | ||
7969
94
58