Skip to content

Commit

Permalink
owmweather: Undo change to One Call API 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gsuarezc committed Nov 28, 2024
1 parent f34a9bf commit 7c9b13a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
3 changes: 2 additions & 1 deletion apps/owmweather/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
0.04: Minor code improvements
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.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
23 changes: 10 additions & 13 deletions apps/owmweather/lib.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
function parseWeather(response) {
let owmData = JSON.parse(response);

let isOwmData = false;
try {
isOwmData = (owmData.lat && owmData.lon) && owmData.current.weather && owmData.current;
} catch (_e) {}
let isOwmData = owmData.coord && owmData.weather && owmData.main;

if (isOwmData) {
let json = require("Storage").readJSON('weather.json') || {};
let weather = {};
weather.time = Date.now();
weather.hum = owmData.current.humidity;
weather.temp = owmData.current.temp;
weather.code = owmData.current.weather[0].id;
weather.wdir = owmData.current.wind_deg;
weather.wind = owmData.current.wind_speed;
weather.loc = owmData.name || "";
weather.txt = owmData.current.weather[0].main;
weather.hpa = owmData.current.pressure || 0;
weather.hum = owmData.main.humidity;
weather.temp = owmData.main.temp;
weather.code = owmData.weather[0].id;
weather.wdir = owmData.wind.deg;
weather.wind = owmData.wind.speed;
weather.loc = owmData.name;
weather.txt = owmData.weather[0].main;
weather.hpa = owmData.main.pressure || 0;

if (weather.wdir != null) {
let deg = weather.wdir;
Expand All @@ -43,7 +40,7 @@ exports.pull = function(completionCallback) {
"location": "London"
};
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){
Bangle.http(uri, {timeout:10000}).then(event => {
let result = parseWeather(event.resp);
Expand Down
2 changes: 1 addition & 1 deletion apps/owmweather/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ "id": "owmweather",
"name": "OpenWeatherMap weather provider",
"shortName":"OWM Weather",
"version": "0.07",
"version": "0.08",
"description": "Pulls weather from OpenWeatherMap (OWM) API",
"icon": "app.png",
"type": "bootloader",
Expand Down

0 comments on commit 7c9b13a

Please sign in to comment.