Skip to content

Commit dfde434

Browse files
authored
Merge pull request espruino#3675 from gsuarezc/master
Undo change to One Call API 3.0
2 parents 352c15b + 5361bcc commit dfde434

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

apps/owmweather/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
0.04: Minor code improvements
55
0.05: Upgrade OWM to One Call API 3.0. Add pressure to weather.json
66
0.06: Fix One Call API 3.0 not returning city names, which are required by the weather app
7-
0.07: Update weather after reconnecting bluetooth if update is due, refactor code
7+
0.07: Update weather after reconnecting bluetooth if update is due, refactor code
8+
0.08: Undo change to One Call API 3.0

apps/owmweather/lib.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
function parseWeather(response) {
22
let owmData = JSON.parse(response);
33

4-
let isOwmData = false;
5-
try {
6-
isOwmData = (owmData.lat && owmData.lon) && owmData.current.weather && owmData.current;
7-
} catch (_e) {}
4+
let isOwmData = owmData.coord && owmData.weather && owmData.main;
85

96
if (isOwmData) {
107
let json = require("Storage").readJSON('weather.json') || {};
118
let weather = {};
129
weather.time = Date.now();
13-
weather.hum = owmData.current.humidity;
14-
weather.temp = owmData.current.temp;
15-
weather.code = owmData.current.weather[0].id;
16-
weather.wdir = owmData.current.wind_deg;
17-
weather.wind = owmData.current.wind_speed;
18-
weather.loc = owmData.name || "";
19-
weather.txt = owmData.current.weather[0].main;
20-
weather.hpa = owmData.current.pressure || 0;
10+
weather.hum = owmData.main.humidity;
11+
weather.temp = owmData.main.temp;
12+
weather.code = owmData.weather[0].id;
13+
weather.wdir = owmData.wind.deg;
14+
weather.wind = owmData.wind.speed;
15+
weather.loc = owmData.name;
16+
weather.txt = owmData.weather[0].main;
17+
weather.hpa = owmData.main.pressure || 0;
2118

2219
if (weather.wdir != null) {
2320
let deg = weather.wdir;
@@ -43,7 +40,7 @@ exports.pull = function(completionCallback) {
4340
"location": "London"
4441
};
4542
let settings = require("Storage").readJSON("owmweather.json", 1);
46-
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;
43+
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;
4744
if (Bangle.http){
4845
Bangle.http(uri, {timeout:10000}).then(event => {
4946
let result = parseWeather(event.resp);

apps/owmweather/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{ "id": "owmweather",
22
"name": "OpenWeatherMap weather provider",
33
"shortName":"OWM Weather",
4-
"version": "0.07",
4+
"version": "0.08",
55
"description": "Pulls weather from OpenWeatherMap (OWM) API",
66
"icon": "app.png",
77
"type": "bootloader",

0 commit comments

Comments
 (0)