mirror of https://github.com/espruino/BangleApps
owmweather: Undo change to One Call API 3.0
parent
f34a9bfc32
commit
7c9b13aa28
|
@ -5,3 +5,4 @@
|
||||||
0.05: Upgrade OWM to One Call API 3.0. Add pressure to weather.json
|
0.05: Upgrade OWM to One Call API 3.0. Add pressure to weather.json
|
||||||
0.06: Fix One Call API 3.0 not returning city names, which are required by the weather app
|
0.06: Fix One Call API 3.0 not returning city names, which are required by the weather app
|
||||||
0.07: Update weather after reconnecting bluetooth if update is due, refactor code
|
0.07: Update weather after reconnecting bluetooth if update is due, refactor code
|
||||||
|
0.08: Undo change to One Call API 3.0
|
|
@ -1,23 +1,20 @@
|
||||||
function parseWeather(response) {
|
function parseWeather(response) {
|
||||||
let owmData = JSON.parse(response);
|
let owmData = JSON.parse(response);
|
||||||
|
|
||||||
let isOwmData = false;
|
let isOwmData = owmData.coord && owmData.weather && owmData.main;
|
||||||
try {
|
|
||||||
isOwmData = (owmData.lat && owmData.lon) && owmData.current.weather && owmData.current;
|
|
||||||
} catch (_e) {}
|
|
||||||
|
|
||||||
if (isOwmData) {
|
if (isOwmData) {
|
||||||
let json = require("Storage").readJSON('weather.json') || {};
|
let json = require("Storage").readJSON('weather.json') || {};
|
||||||
let weather = {};
|
let weather = {};
|
||||||
weather.time = Date.now();
|
weather.time = Date.now();
|
||||||
weather.hum = owmData.current.humidity;
|
weather.hum = owmData.main.humidity;
|
||||||
weather.temp = owmData.current.temp;
|
weather.temp = owmData.main.temp;
|
||||||
weather.code = owmData.current.weather[0].id;
|
weather.code = owmData.weather[0].id;
|
||||||
weather.wdir = owmData.current.wind_deg;
|
weather.wdir = owmData.wind.deg;
|
||||||
weather.wind = owmData.current.wind_speed;
|
weather.wind = owmData.wind.speed;
|
||||||
weather.loc = owmData.name || "";
|
weather.loc = owmData.name;
|
||||||
weather.txt = owmData.current.weather[0].main;
|
weather.txt = owmData.weather[0].main;
|
||||||
weather.hpa = owmData.current.pressure || 0;
|
weather.hpa = owmData.main.pressure || 0;
|
||||||
|
|
||||||
if (weather.wdir != null) {
|
if (weather.wdir != null) {
|
||||||
let deg = weather.wdir;
|
let deg = weather.wdir;
|
||||||
|
@ -43,7 +40,7 @@ exports.pull = function(completionCallback) {
|
||||||
"location": "London"
|
"location": "London"
|
||||||
};
|
};
|
||||||
let settings = require("Storage").readJSON("owmweather.json", 1);
|
let settings = require("Storage").readJSON("owmweather.json", 1);
|
||||||
let uri = "https://api.openweathermap.org/data/3.0/onecall?lat=" + location.lat.toFixed(2) + "&lon=" + location.lon.toFixed(2) + "&exclude=minutely,hourly,daily,alerts&appid=" + settings.apikey;
|
let uri = "https://api.openweathermap.org/data/2.5/weather?lat=" + location.lat.toFixed(2) + "&lon=" + location.lon.toFixed(2) + "&exclude=hourly,daily&appid=" + settings.apikey;
|
||||||
if (Bangle.http){
|
if (Bangle.http){
|
||||||
Bangle.http(uri, {timeout:10000}).then(event => {
|
Bangle.http(uri, {timeout:10000}).then(event => {
|
||||||
let result = parseWeather(event.resp);
|
let result = parseWeather(event.resp);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ "id": "owmweather",
|
{ "id": "owmweather",
|
||||||
"name": "OpenWeatherMap weather provider",
|
"name": "OpenWeatherMap weather provider",
|
||||||
"shortName":"OWM Weather",
|
"shortName":"OWM Weather",
|
||||||
"version": "0.07",
|
"version": "0.08",
|
||||||
"description": "Pulls weather from OpenWeatherMap (OWM) API",
|
"description": "Pulls weather from OpenWeatherMap (OWM) API",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"type": "bootloader",
|
"type": "bootloader",
|
||||||
|
|
Loading…
Reference in New Issue