From dcec8ead0992665962901767b1cbfd22bdbb3b77 Mon Sep 17 00:00:00 2001 From: Rengyr Date: Sat, 17 May 2025 18:29:26 +0200 Subject: [PATCH 1/6] Weather: Unify formatting and more modern style of javascript --- apps/weather/app.js | 20 +++--- apps/weather/clkinfo.js | 7 +- apps/weather/lib.js | 143 +++++++++++++++++++-------------------- apps/weather/settings.js | 38 +++++------ apps/weather/widget.js | 42 ++++++------ 5 files changed, 124 insertions(+), 126 deletions(-) diff --git a/apps/weather/app.js b/apps/weather/app.js index 923e63bbfe..7f42e60bbc 100644 --- a/apps/weather/app.js +++ b/apps/weather/app.js @@ -16,24 +16,24 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [ render: l => { if (!current || current.uv === undefined) return; const uv = Math.min(parseInt(current.uv), 11); // Cap at 11 - + // UV color thresholds: [max_value, color] based on WHO standards const colors = [[2,"#0F0"], [5,"#FF0"], [7,"#F80"], [10,"#F00"], [11,"#F0F"]]; const color = colors.find(c => uv <= c[0])[1]; - + // Setup and measure label g.setFont("6x8").setFontAlign(-1, 0); const label = "UV: "; const labelW = g.stringWidth(label); - + // Calculate centered position (4px block + 1px spacing) * blocks - last spacing const totalW = labelW + uv * 5 - (uv > 0 ? 1 : 0); const x = l.x + (l.w - totalW) / 2; const y = l.y + l.h+6; - + // Draw label g.setColor(g.theme.fg).drawString(label, x, y); - + // Draw UV blocks g.setColor(color); for (let i = 0; i < uv; i++) { @@ -58,7 +58,7 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [ {type: "txt", font: "6x8", pad: 2, halign: 1, label: /*LANG*/"Hum:"}, {type: "txt", font: "9%", pad: 2, halign: 1, id: "hum", label: "000%"}, ]}, - + {filly: 1}, {type: "txt", font: "6x8", pad: 2, halign: -1, label: /*LANG*/"Wind"}, {type: "h", halign: -1, c: [ @@ -79,7 +79,7 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [ ]}, {lazy: true}); function formatDuration(millis) { - let pluralize = (n, w) => n + " " + w + (n == 1 ? "" : "s"); + let pluralize = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`; if (millis < 60000) return /*LANG*/"< 1 minute"; if (millis < 3600000) return pluralize(Math.floor(millis/60000), /*LANG*/"minute"); if (millis < 86400000) return pluralize(Math.floor(millis/3600000), /*LANG*/"hour"); @@ -98,11 +98,11 @@ function draw() { }else{ layout.feelslike.label = feelsLikeTemp[1]+feelsLikeTemp[2]; } - - layout.hum.label = current.hum+"%"; + + layout.hum.label = `${current.hum}%`; const wind = locale.speed(current.wind).match(/^(\D*\d*)(.*)$/); layout.wind.label = wind[1]; - layout.windUnit.label = wind[2] + " " + (current.wrose||'').toUpperCase(); + layout.windUnit.label = `${wind[2]} ${(current.wrose||'').toUpperCase()}`; layout.cond.label = current.txt.charAt(0).toUpperCase()+(current.txt||'').slice(1); layout.loc.label = current.loc; layout.updateTime.label = `${formatDuration(Date.now() - current.time)} ago`; // How to autotranslate this and similar? diff --git a/apps/weather/clkinfo.js b/apps/weather/clkinfo.js index eaf9556e04..b60aa6daae 100644 --- a/apps/weather/clkinfo.js +++ b/apps/weather/clkinfo.js @@ -1,5 +1,4 @@ - -(function() { +(() => { var weather; var weatherLib = require("weather"); @@ -8,9 +7,9 @@ if(weather){ weather.temp = require("locale").temp(weather.temp-273.15); weather.feels = require("locale").temp(weather.feels-273.15); - weather.hum = weather.hum + "%"; + weather.hum = `${weather.hum}%`; weather.wind = require("locale").speed(weather.wind).match(/^(\D*\d*)(.*)$/); - weather.wind = Math.round(weather.wind[1]) + "kph"; + weather.wind = `${Math.round(weather.wind[1])}kph`; } else { weather = { temp: "?", diff --git a/apps/weather/lib.js b/apps/weather/lib.js index 9505cbafef..18f149c150 100644 --- a/apps/weather/lib.js +++ b/apps/weather/lib.js @@ -1,5 +1,5 @@ -const storage = require('Storage'); -const B2 = process.env.HWVERSION===2; +const storage = require("Storage"); +const B2 = process.env.HWVERSION === 2; let expiryTimeout; function scheduleExpiry(json) { @@ -7,7 +7,7 @@ function scheduleExpiry(json) { clearTimeout(expiryTimeout); expiryTimeout = undefined; } - let expiry = "expiry" in json ? json.expiry : 2*3600000; + let expiry = "expiry" in json ? json.expiry : 2 * 3600000; if (json.weather && json.weather.time && expiry) { let t = json.weather.time + expiry - Date.now(); expiryTimeout = setTimeout(update, t); @@ -15,7 +15,7 @@ function scheduleExpiry(json) { } function update(weatherEvent) { - let json = storage.readJSON('weather.json')||{}; + let json = storage.readJSON("weather.json") || {}; if (weatherEvent) { let weather = weatherEvent.clone(); @@ -24,92 +24,90 @@ function update(weatherEvent) { if (weather.wdir != null) { // Convert numeric direction into human-readable label let deg = weather.wdir; - while (deg<0 || deg>360) { - deg = (deg+360)%360; + while (deg < 0 || deg > 360) { + deg = (deg + 360) % 360; } - weather.wrose = ['n','ne','e','se','s','sw','w','nw','n'][Math.floor((deg+22.5)/45)]; + weather.wrose = ["n", "ne", "e", "se", "s", "sw", "w", "nw", "n"][Math.floor((deg + 22.5) / 45)]; } json.weather = weather; - } - else { + } else { delete json.weather; } - - storage.write('weather.json', json); + storage.write("weather.json", json); scheduleExpiry(json); exports.emit("update", json.weather); } exports.update = update; const _GB = global.GB; global.GB = (event) => { - if (event.t==="weather") update(event); + if (event.t === "weather") update(event); if (_GB) setTimeout(_GB, 0, event); }; -exports.get = function() { - return (storage.readJSON('weather.json')||{}).weather; -} +exports.get = () => { + return (storage.readJSON("weather.json") || {}).weather; +}; -scheduleExpiry(storage.readJSON('weather.json')||{}); +scheduleExpiry(storage.readJSON("weather.json") || {}); function getPalette(monochrome, ovr) { var palette; - if(monochrome) { + if (monochrome) { palette = { - sun: '#FFF', - cloud: '#FFF', - bgCloud: '#FFF', - rain: '#FFF', - lightning: '#FFF', - snow: '#FFF', - mist: '#FFF', - background: '#000' + sun: "#FFF", + cloud: "#FFF", + bgCloud: "#FFF", + rain: "#FFF", + lightning: "#FFF", + snow: "#FFF", + mist: "#FFF", + background: "#000", }; } else { if (B2) { if (ovr.theme.dark) { palette = { - sun: '#FF0', - cloud: '#FFF', - bgCloud: '#777', // dithers on B2, but that's ok - rain: '#0FF', - lightning: '#FF0', - snow: '#FFF', - mist: '#FFF' + sun: "#FF0", + cloud: "#FFF", + bgCloud: "#777", // dithers on B2, but that's ok + rain: "#0FF", + lightning: "#FF0", + snow: "#FFF", + mist: "#FFF", }; } else { palette = { - sun: '#FF0', - cloud: '#777', // dithers on B2, but that's ok - bgCloud: '#000', - rain: '#00F', - lightning: '#FF0', - snow: '#0FF', - mist: '#0FF' + sun: "#FF0", + cloud: "#777", // dithers on B2, but that's ok + bgCloud: "#000", + rain: "#00F", + lightning: "#FF0", + snow: "#0FF", + mist: "#0FF", }; } } else { if (ovr.theme.dark) { palette = { - sun: '#FE0', - cloud: '#BBB', - bgCloud: '#777', - rain: '#0CF', - lightning: '#FE0', - snow: '#FFF', - mist: '#FFF' + sun: "#FE0", + cloud: "#BBB", + bgCloud: "#777", + rain: "#0CF", + lightning: "#FE0", + snow: "#FFF", + mist: "#FFF", }; } else { palette = { - sun: '#FC0', - cloud: '#000', - bgCloud: '#777', - rain: '#07F', - lightning: '#FC0', - snow: '#CCC', - mist: '#CCC' + sun: "#FC0", + cloud: "#000", + bgCloud: "#777", + rain: "#07F", + lightning: "#FC0", + snow: "#CCC", + mist: "#CCC", }; } } @@ -117,10 +115,10 @@ function getPalette(monochrome, ovr) { return palette; } -exports.getColor = function(code) { +exports.getColor = (code) => { const codeGroup = Math.round(code / 100); const palette = getPalette(0, g); - const cloud = g.blendColor(palette.cloud, palette.bgCloud, .5); //theme independent + const cloud = g.blendColor(palette.cloud, palette.bgCloud, 0.5); //theme independent switch (codeGroup) { case 2: return g.blendColor(cloud, palette.lightning, .5); case 3: return palette.rain; @@ -144,7 +142,7 @@ exports.getColor = function(code) { } default: return cloud; } -} +}; /** * @@ -158,9 +156,9 @@ exports.getColor = function(code) { * @param ovr Graphics instance (or undefined for g) * @param monochrome If true, produce a monochromatic icon */ -exports.drawIcon = function(cond, x, y, r, ovr, monochrome) { +exports.drawIcon = (cond, x, y, r, ovr, monochrome) => { var palette; - if(!ovr) ovr = g; + if (!ovr) ovr = g; palette = getPalette(monochrome, ovr); @@ -257,7 +255,7 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) { function drawSnow(x, y, r) { function rotatePoints(points, pivotX, pivotY, angle) { - for(let i = 0; i {}; txt = txt.toLowerCase(); @@ -336,7 +334,8 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) { if (txt.includes("few clouds")) return drawFewClouds; if (txt.includes("scattered clouds")) return drawCloud; if (txt.includes("clouds")) return drawBrokenClouds; - if (txt.includes("mist") || + if ( + txt.includes("mist") || txt.includes("smoke") || txt.includes("haze") || txt.includes("sand") || @@ -344,16 +343,17 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) { txt.includes("fog") || txt.includes("ash") || txt.includes("squalls") || - txt.includes("tornado")) { + txt.includes("tornado") + ) { return drawMist; } return drawUnknown; } /* - * Choose weather icon to display based on weather conditition code - * https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2 - */ + * Choose weather icon to display based on weather condition code + * https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2 + */ function chooseIconByCode(code) { const codeGroup = Math.round(code / 100); switch (codeGroup) { @@ -382,16 +382,15 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) { } function chooseIcon(cond) { - if (typeof (cond)==="object") { + if (typeof cond === "object") { if ("code" in cond) return chooseIconByCode(cond.code); if ("txt" in cond) return chooseIconByTxt(cond.txt); - } else if (typeof (cond)==="number") { + } else if (typeof cond === "number") { return chooseIconByCode(cond.code); - } else if (typeof (cond)==="string") { + } else if (typeof cond === "string") { return chooseIconByTxt(cond.txt); } return drawUnknown; } chooseIcon(cond)(x, y, r); - }; diff --git a/apps/weather/settings.js b/apps/weather/settings.js index 7e0bb24c82..9f39c00df3 100644 --- a/apps/weather/settings.js +++ b/apps/weather/settings.js @@ -1,31 +1,31 @@ -(function(back) { - const storage = require('Storage'); - let settings = storage.readJSON('weather.json', 1) || {}; +(back) => { + const storage = require("Storage"); + let settings = storage.readJSON("weather.json", 1) || {}; function save(key, value) { settings[key] = value; - storage.write('weather.json', settings); + storage.write("weather.json", settings); } E.showMenu({ - '': { 'title': 'Weather' }, - 'Expiry': { - value: "expiry" in settings ? settings["expiry"] : 2*3600000, + "": { "title": "Weather" }, + "Expiry": { + value: "expiry" in settings ? settings.expiry : 2 * 3600000, min: 0, - max : 24*3600000, - step: 15*60000, - format: x => { - if (x == 0) return "none"; - if (x < 3600000) return Math.floor(x/60000) + "m"; - if (x < 86400000) return Math.floor(x/36000)/100 + "h"; + max: 24 * 3600000, + step: 15 * 60000, + format: (x) => { + if (x === 0) return "none"; + if (x < 3600000) return `${Math.floor(x / 60000)}m`; + if (x < 86400000) return `${Math.floor(x / 36000) / 100}h`; }, - onchange: x => save('expiry', x), + onchange: (x) => save("expiry", x), }, - 'Hide Widget': { + "Hide Widget": { value: "hide" in settings ? settings.hide : false, onchange: () => { - settings.hide = !settings.hide - save('hide', settings.hide); + settings.hide = !settings.hide; + save("hide", settings.hide); }, }, - '< Back': back, + "< Back": back, }); -}) +}; diff --git a/apps/weather/widget.js b/apps/weather/widget.js index 2905d776b4..be0ca838fe 100644 --- a/apps/weather/widget.js +++ b/apps/weather/widget.js @@ -1,53 +1,53 @@ (() => { - const weather = require('weather'); - + const weather = require("weather"); + var dirty = false; - + let settings; function loadSettings() { - settings = require('Storage').readJSON('weather.json', 1) || {}; + settings = require("Storage").readJSON("weather.json", 1) || {}; } function setting(key) { if (!settings) { loadSettings(); } const DEFAULTS = { - 'expiry': 2*3600000, - 'hide': false + "expiry": 2*3600000, + "hide": false }; return (key in settings) ? settings[key] : DEFAULTS[key]; } weather.on("update", w => { - if (setting('hide')) return; + if (setting("hide")) return; if (w) { - if (!WIDGETS["weather"].width) { - WIDGETS["weather"].width = 20; + if (!WIDGETS.weather.width) { + WIDGETS.weather.width = 20; Bangle.drawWidgets(); } else if (Bangle.isLCDOn()) { - WIDGETS["weather"].draw(); + WIDGETS.weather.draw(); } else { dirty = true; } } else { - WIDGETS["weather"].width = 0; + WIDGETS.weather.width = 0; Bangle.drawWidgets(); } }); - Bangle.on('lcdPower', on => { - if (on && dirty && !setting('hide')) { - WIDGETS["weather"].draw(); + Bangle.on("lcdPower", on => { + if (on && dirty && !setting("hide")) { + WIDGETS.weather.draw(); dirty = false; } }); - WIDGETS["weather"] = { + WIDGETS.weather = { area: "tl", - width: weather.get() && !setting('hide') ? 20 : 0, + width: weather.get() && !setting("hide") ? 20 : 0, draw: function() { - if (setting('hide')) return; + if (setting("hide")) return; const w = weather.get(); if (!w) return; g.reset(); @@ -56,17 +56,17 @@ weather.drawIcon(w, this.x+10, this.y+8, 7.5); } if (w.temp) { - let t = require('locale').temp(w.temp-273.15); // applies conversion + let t = require("locale").temp(w.temp-273.15); // applies conversion t = t.match(/[\d\-]*/)[0]; // but we have no room for units g.reset(); g.setFontAlign(0, 1); // center horizontally at bottom of widget - g.setFont('6x8', 1); + g.setFont("6x8", 1); g.drawString(t, this.x+10, this.y+24); } }, - reload:function() { + reload:() => { loadSettings(); - WIDGETS["weather"].redraw(); + WIDGETS.weather.redraw(); }, }; })(); From 42bf5b3cbd7e5f28c045b965cc7c7dcd44c9f256 Mon Sep 17 00:00:00 2001 From: Rengyr Date: Sat, 17 May 2025 18:29:26 +0200 Subject: [PATCH 2/6] Weather: Add new weather parsing in Weather App --- apps/weather/ChangeLog | 6 + apps/weather/README.md | 87 +++++++++--- apps/weather/lib.js | 277 +++++++++++++++++++++++++++++++++---- apps/weather/metadata.json | 4 +- apps/weather/settings.js | 40 +++++- apps/weather/widget.js | 2 +- 6 files changed, 367 insertions(+), 49 deletions(-) diff --git a/apps/weather/ChangeLog b/apps/weather/ChangeLog index dcbbab2edc..81c3732396 100644 --- a/apps/weather/ChangeLog +++ b/apps/weather/ChangeLog @@ -26,3 +26,9 @@ 0.27: Add UV index display 0.28: Fix UV positioning, hide when 0 0.29: Add feels-like temperature data and clock_info +0.30: Refactor code to more modern javascript style + Split settings and weather data into two files in storage + Add support for new version of weather data and forecast from GadgetBridge (requires version 0.86.0 or higher) + Add support to automatically fetch weather at time interval defined in settings (requires GadgetBridge version 0.86.0 or higher) + Add button to settings to force fetch weather data (requires GadgetBridge version 0.86.0 or higher) + Add new API to get weather from Weather App for other Apps diff --git a/apps/weather/README.md b/apps/weather/README.md index 7b29f90ddc..9c692c011c 100644 --- a/apps/weather/README.md +++ b/apps/weather/README.md @@ -3,7 +3,7 @@ This allows your Bangle.js to display weather reports from the Gadgetbridge app for an Android phone, or by using the iOS shortcut below to push weather information. It adds a widget with a weather pictogram and the temperature. -It also adds a ClockInfo list to Bangle.js. +It also adds a ClockInfo list to Bangle.js. You can view the full report through the app: ![Screenshot](screenshot.png) @@ -12,35 +12,35 @@ You can view the full report through the app: Use the iOS shortcut [here](https://www.icloud.com/shortcuts/73be0ce1076446f3bdc45a5707de5c4d). The shortcut uses Apple Weather for weather updates, and sends a notification, which is read by Bangle.js. To push weather every hour, or interval, you will need to create a shortcut automation for every time you want to push the weather. - ## Android Setup -1. Install [Gadgetbridge for Android](https://f-droid.org/packages/nodomain.freeyourgadget.gadgetbridge/) on your phone. -2. Set up [Gadgetbridge weather reporting](https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Weather). - -If using the `Bangle.js Gadgetbridge` app on your phone (as opposed to the standard F-Droid `Gadgetbridge`) you need to set the package name -to `com.espruino.gadgetbridge.banglejs` in the settings of the weather app (`settings -> gadgetbridge support -> package name`). +1. Install [Gadgetbridge for Android](https://f-droid.org/packages/nodomain.freeyourgadget.gadgetbridge/) on your phone +2. Set up [Gadgetbridge weather reporting](https://gadgetbridge.org/basics/features/weather/) ### Android Weather Apps -There are two weather apps for Android that can connect with Gadgetbridge: +There are multiple weather apps for Android that can connect with Gadgetbridge: * Tiny Weather Forecast Germany - * F-Droid - https://f-droid.org/en/packages/de.kaffeemitkoffein.tinyweatherforecastgermany/ - * Source code - https://codeberg.org/Starfish/TinyWeatherForecastGermany - + * F-Droid - https://f-droid.org/en/packages/de.kaffeemitkoffein.tinyweatherforecastgermany/ + * Source code - https://codeberg.org/Starfish/TinyWeatherForecastGermany + * QuickWeather - * F-Droid - https://f-droid.org/en/packages/com.ominous.quickweather/ - * Google Play - https://play.google.com/store/apps/details?id=com.ominous.quickweather - * Source code - https://github.com/TylerWilliamson/QuickWeather - + * F-Droid - https://f-droid.org/en/packages/com.ominous.quickweather/ + * Google Play - https://play.google.com/store/apps/details?id=com.ominous.quickweather + * Source code - https://github.com/TylerWilliamson/QuickWeather + +* Breezy Weather + * F-Droid - https://f-droid.org/en/packages/org.breezyweather/ + * Source code - https://github.com/breezy-weather/breezy-weather + ### Tiny Weather Forecast Germany Even though Tiny Weather Forecast Germany is made for Germany, it can be used around the world. To do this: - + 1. Tap on the three dots in the top right hand corner and go to settings 2. Go down to Location and tap on the checkbox labeled "Use location services". You may also want to check on the "Check Location checkbox". Alternatively, you may select the "manual" checkbox and choose your location. -3. Scroll down further to the "other" section and tap "Gadgetbridge support". Then tap on "Enable". You may also choose to tap on "Send current time". +3. Scroll down further to the "other" section and tap "Gadgetbridge support". Then tap on "Enable". You may also choose to tap on "Send current time". 4. If you're using the specific Gadgetbridge for Bangle.JS app, you'll want to tap on "Package name." In the dialog box that appears, you'll want to put in "com.espruino.gadgetbridge.banglejs" without the quotes. If you're using the original Gadgetbridge, leave this as the default. ### QuickWeather @@ -51,9 +51,17 @@ If you're using OpenWeatherMap you will need the "One Call By Call" plan, which When you first load QuickWeather, it will take you through the setup process. You will fill out all the required information as well as put your API key in. If you do not have the "One Call By Call", or commonly known as "One Call", API, you will need to sign up for that. QuickWeather will work automatically with both the main version of Gadgetbridge and Gadgetbridge for Bangle.JS. +### Breezy Weather + +Enabling connection to Gadgetbridge: + +1. Tap on the three dots in the top right hand corner and go to settings +2. Find "Widgets & Live wallpaper" settings +3. Under "Data sharing" tap on "Send Gadgetbridge data" and enable for Gadgetbridge flavor you are using + ### Weather Notification -**Note:** at one time, the Weather Notification app also worked with Gadgetbridge. However, many users are reporting it's no longer seeing the OpenWeatherMap API key as valid. The app has not received any updates since August of 2020, and may be unmaintained. +**Note:** at one time, the Weather Notification app also worked with Gadgetbridge. However, many users are reporting it's no longer seeing the OpenWeatherMap API key as valid. The app has not received any updates since August of 2020, and may be unmaintained. ## Clock Infos @@ -67,7 +75,9 @@ Adds: ## Settings -* Expiration timespan can be set after which the local weather data is considered as invalid +* Expiration time span can be set after which the local weather data is considered as invalid +* Automatic weather data request interval can be set (weather data are pushed to Bangle automatically, but this can help in cases when it fails) (requires Gadgetbridge v0.86+) +* Forecast weather data can be enabled (this requires other App to use the data, Weather App itself doesn't show the forecast data) (requires Gadgetbridge v0.86+) * Widget can be hidden * To change the units for wind speed, you can install the [`Languages app`](https://banglejs.com/apps/?id=locale) which allows you to choose the units used for speed/distance/temperature and so on. @@ -76,3 +86,42 @@ allows you to choose the units used for speed/distance/temperature and so on. * BTN2: opens the launcher (Bangle.js 1) * BTN: opens the launcher (Bangle.js 2) + +## Weather App API + +Weather App can provide weather and forecast data to other Apps. + +* Get weather data without forecast: + ```javascript + const weather = require("weather"); + weatherData = weather.getWeather(false); // or weather.get() + ``` + +* Get weather data with forecast (needs forecast enabled in settings): + ```javascript + const weather = require("weather"); + weatherData = weather.getWeather(true); + ``` + +* Fetch new data from Gadgetbridge: + ```javascript + const weather = require("weather"); + weather.updateWeather(false); // Can set to true if we want to ignore debounce + ``` + +* React to updated weather data: + ```javascript + const weather = require("weather"); + + // For weather data without forecast + weather.on("update", () => { + currentData = weather.getWeather(false); + // console.log(currentData); + } + + // For weather data with forecast + weather.on("update2", () => { + currentData = weather.getWeather(true); + // console.log(currentData); + } + ``` diff --git a/apps/weather/lib.js b/apps/weather/lib.js index 18f149c150..604e76fca9 100644 --- a/apps/weather/lib.js +++ b/apps/weather/lib.js @@ -2,43 +2,147 @@ const storage = require("Storage"); const B2 = process.env.HWVERSION === 2; let expiryTimeout; -function scheduleExpiry(json) { +function scheduleExpiry() { if (expiryTimeout) { clearTimeout(expiryTimeout); expiryTimeout = undefined; } - let expiry = "expiry" in json ? json.expiry : 2 * 3600000; - if (json.weather && json.weather.time && expiry) { - let t = json.weather.time + expiry - Date.now(); - expiryTimeout = setTimeout(update, t); + + const json = storage.readJSON("weatherSetting.json") || {}; + const expiry = "expiry" in json ? json.expiry : 2 * 3600000; + expiryTimeout = setTimeout(() => { + storage.write("weather.json", { t: "weather", weather: undefined }); + storage.write("weather2.json", {}); + }, expiry); +} + +let refreshTimeout; +function scheduleRefresh() { + if (refreshTimeout) { + clearTimeout(refreshTimeout); + refreshTimeout = undefined; } + const json = storage.readJSON("weatherSetting.json") || {}; + const refresh = "refresh" in json ? json.refresh : 0; + if (refresh === 0) { + return; + } + refreshTimeout = setTimeout(() => { + updateWeather(false); + scheduleRefresh(); + }, refresh); +} + +const angles = ["n", "ne", "e", "se", "s", "sw", "w", "nw", "n"]; +function windDirection(angle) { + return angles[Math.floor((angle + 22.5) / 45)]; } function update(weatherEvent) { - let json = storage.readJSON("weather.json") || {}; + if (weatherEvent == null) { + return; + } + + if (weatherEvent.t !== "weather") { + return; + } + + const weatherSetting = storage.readJSON("weatherSetting.json") || {}; + + if (weatherEvent.v == null || weatherEvent.v === 1) { + let json = { "t": "weather", "weather": weatherEvent.clone() }; + let weather = json.weather; - if (weatherEvent) { - let weather = weatherEvent.clone(); - delete weather.t; weather.time = Date.now(); if (weather.wdir != null) { - // Convert numeric direction into human-readable label - let deg = weather.wdir; - while (deg < 0 || deg > 360) { - deg = (deg + 360) % 360; - } - weather.wrose = ["n", "ne", "e", "se", "s", "sw", "w", "nw", "n"][Math.floor((deg + 22.5) / 45)]; + weather.wrose = windDirection(weather.wdir); } - json.weather = weather; - } else { - delete json.weather; + storage.write("weather.json", json); + exports.emit("update", weather); + + // Request forecast if supported by GadgetBridge and set in settings + if (weatherEvent.v != null && (weatherSetting.forecast ?? false)) { + updateWeather(true); + } + + // Either GadgetBridge doesn't support v2 and/or we don't need forecast, so we use this event for refresh scheduling + if (weatherEvent.v == null || (weatherSetting.forecast ?? false) === false) { + weatherSetting.time = Date.now(); + storage.write("weatherSetting.json", weatherSetting); + + scheduleExpiry(); + scheduleRefresh(); + } + } else if (weatherEvent.v === 2) { + weatherSetting.time = Date.now(); + storage.write("weatherSetting.json", weatherSetting); + + // Store binary data for parsing when requested by other apps later + let cloned = weatherEvent.clone(); + cloned.time = weatherSetting.time; + storage.write("weather2.json", cloned); + + // If we stored weather v1 recently, we don't need to parse non-forecast from v2 + // Otherwise we need to parse part of it to refresh weather1.json + let weather1 = storage.readJSON("weather.json") ?? {}; + if (weather1.weather == null || weather1.weather.time == null || Date.now() - weather1.weather.time >= 60 * 1000) { + weather1 = undefined; // Clear memory + const weather2 = decodeWeatherV2(weatherEvent, true, false); + + // Store simpler weather for apps that doesn't need forecast or backward compatibility + const weather = downgradeWeatherV2(weather2); + storage.write("weather.json", weather); + } + + cloned = undefined; // Clear memory + + scheduleExpiry(); + scheduleRefresh(); + + exports.emit("update2"); } +} + +function updateWeather(force) { + const settings = storage.readJSON("weatherSetting.json") || {}; + + let lastFetch = settings.time ?? 0; + + // More than 5 minutes + if (force || Date.now() - lastFetch >= 5 * 60 * 1000) { + Bluetooth.println(""); + Bluetooth.println(JSON.stringify({ t: "weather", v: 2, f: settings.forecast ?? false })); + } +} + +function getWeather(forecast) { + const weatherSetting = storage.readJSON("weatherSetting.json") || {}; + + if (forecast === false || !(weatherSetting.forecast ?? false)) { + // biome-ignore lint/complexity/useOptionalChain: not supported by Espruino + return (storage.readJSON("weather.json") ?? {}).weather; + } else { + const json2 = storage.readJSON("weather2.json"); + if (json2 == null) { + // Fallback in case no weather v2 exists, but we have weather v1 + // biome-ignore lint/complexity/useOptionalChain: not supported by Espruino + return (storage.readJSON("weather.json") ?? {}).weather; + } + + if (json2.d == null) { + // We have already parsed weather v2 + return json2; + } + + // We have weather v2, but not decoded + const decoded = decodeWeatherV2(json2, true, true); + storage.write("weather2.json", decoded); - storage.write("weather.json", json); - scheduleExpiry(json); - exports.emit("update", json.weather); + return decoded; + } } + exports.update = update; const _GB = global.GB; global.GB = (event) => { @@ -46,11 +150,134 @@ global.GB = (event) => { if (_GB) setTimeout(_GB, 0, event); }; -exports.get = () => { - return (storage.readJSON("weather.json") || {}).weather; -}; +exports.updateWeather = updateWeather; +exports.get = () => getWeather(false); +exports.getWeather = getWeather; + +scheduleRefresh(); -scheduleExpiry(storage.readJSON("weather.json") || {}); +function decodeWeatherV2(jsonData, canDestroyArgument, parseForecast) { + let time; + if (jsonData != null && jsonData.time != null) { + time = Math.round(jsonData.time); + } else { + time = Math.round(Date.now()); + } + + // Check if we have data to parse + if (jsonData == null || jsonData.d == null) { + return { t: "weather2", v: 2, time: time }; + } + + // This needs to be kept in sync with GadgetBridge + const weatherCodes = [ + [200, 201, 202, 210, 211, 212, 221, 230, 231, 232], + [300, 301, 302, 310, 311, 312, 313, 314, 321], + [], + [500, 501, 502, 503, 504, 511, 520, 521, 522, 531], + [600, 601, 602, 611, 612, 613, 615, 616, 620, 621, 622], + [701, 711, 721, 731, 741, 751, 761, 762, 771, 781], + [800, 801, 802, 803, 804], + ]; + const mapWCode = (code) => { + return weatherCodes[code >> 5][code & 0x1f]; + }; + + const buffer = E.toArrayBuffer(atob(jsonData.d)); + const dataView = new DataView(buffer); + + if (canDestroyArgument) { + delete jsonData.d; // Free some memory if we can + } + + const weather = { + t: "weather2", + v: 2, + time: time, + temp: dataView.getInt8(0), + hi: dataView.getInt8(1), + lo: dataView.getInt8(2), + hum: dataView.getUint8(3), + rain: dataView.getUint8(4), + uv: dataView.getUint8(5) / 10, + code: mapWCode(dataView.getUint8(6)), + txt: jsonData.c, + wind: dataView.getUint16(7, true) / 100, + wdir: dataView.getUint16(9, true), + loc: jsonData.l, + dew: dataView.getInt8(11), + pres: dataView.getUint16(12, true) / 10, + cloud: dataView.getUint8(14), + visib: dataView.getUint32(15, true) / 10, + sunrise: dataView.getUint32(19, true), + sunset: dataView.getUint32(23, true), + moonrise: dataView.getUint32(27, true), + moonset: dataView.getUint32(31, true), + moonphase: dataView.getUint16(35, true), + feel: dataView.getInt8(37, true), + }; + weather.wrose = windDirection(weather.wdir); + + let offset = 38; + if (offset < buffer.length && parseForecast) { + // We have forecast data + + // Hourly forecast + const hoursAmount = dataView.getUint8(offset++); + + const timestampBase = dataView.getUint32(offset, true); + offset += 4; + + weather.hourfcast = { + time: [].map.call(new Uint8Array(buffer, offset, hoursAmount), (v) => timestampBase + (v / 10) * 3600), + temp: new Int8Array(buffer, offset + hoursAmount, hoursAmount), + code: [].map.call(new Uint8Array(buffer, offset + hoursAmount * 2, hoursAmount), mapWCode), + wind: new Uint8Array(buffer, offset + hoursAmount * 3, hoursAmount), + wdir: [].map.call(new Uint8Array(buffer, offset + hoursAmount * 4, hoursAmount), (v) => v * 2), + wrose: [].map.call(new Uint8Array(buffer, offset + hoursAmount * 4, hoursAmount), (v) => windDirection(v * 2)), + rain: new Uint8Array(buffer, offset + hoursAmount * 5, hoursAmount), + }; + offset += hoursAmount * 6; + + // Daily forecast + const daysAmount = dataView.getUint8(offset++); + + weather.dayfcast = { + hi: new Int8Array(buffer, offset, daysAmount), + lo: new Int8Array(buffer, offset + daysAmount, daysAmount), + code: [].map.call(new Uint8Array(buffer, offset + daysAmount * 2, daysAmount), mapWCode), + wind: new Uint8Array(buffer, offset + daysAmount * 3, daysAmount), + wdir: [].map.call(new Uint8Array(buffer, offset + daysAmount * 4, daysAmount), (v) => v * 2), + wrose: [].map.call(new Uint8Array(buffer, offset + daysAmount * 4, daysAmount), (v) => windDirection(v * 2)), + rain: new Uint8Array(buffer, offset + daysAmount * 5, daysAmount), + }; + } + + return weather; +} + +function downgradeWeatherV2(weather2) { + const json = { t: "weather" }; + + json.weather = { + v: 1, + time: weather2.time, + temp: weather2.temp + 273, + hi: weather2.hi + 273, + lo: weather2.lo + 273, + hum: weather2.hum, + rain: weather2.rain, + uv: weather2.uv, + code: weather2.code, + txt: weather2.txt, + wind: weather2.wind, + wdir: weather2.wdir, + wrose: weather2.wrose, + loc: weather2.loc, + }; + + return json; +} function getPalette(monochrome, ovr) { var palette; diff --git a/apps/weather/metadata.json b/apps/weather/metadata.json index 1781d7fc02..86d41b038b 100644 --- a/apps/weather/metadata.json +++ b/apps/weather/metadata.json @@ -1,7 +1,7 @@ { "id": "weather", "name": "Weather", - "version": "0.29", + "version": "0.30", "description": "Show Gadgetbridge/iOS weather report", "icon": "icon.png", "screenshots": [{"url":"screenshot.png"}], @@ -16,5 +16,5 @@ {"name":"weather.settings.js","url":"settings.js"}, {"name":"weather.clkinfo.js","url":"clkinfo.js"} ], - "data": [{"name":"weather.json"}] + "data": [{"name":"weatherSetting.json"},{"name":"weather.json"},{"name":"weather2.json"}] } diff --git a/apps/weather/settings.js b/apps/weather/settings.js index 9f39c00df3..f0b43b678f 100644 --- a/apps/weather/settings.js +++ b/apps/weather/settings.js @@ -1,10 +1,24 @@ (back) => { const storage = require("Storage"); - let settings = storage.readJSON("weather.json", 1) || {}; + let settings = storage.readJSON("weatherSetting.json", 1); + + // Handle transition from old weather.json to new weatherSetting.json + if (settings == null) { + const settingsOld = storage.readJSON("weather.json", 1) || {}; + settings = { + expiry: "expiry" in settingsOld ? settingsOld.expiry : 2 * 3600000, + hide: "hide" in settingsOld ? settingsOld.hide : false, + }; + if (settingsOld != null && settingsOld.weather != null && settingsOld.weather.time != null) { + settings.time = settingsOld.weather.time; + } + } + function save(key, value) { settings[key] = value; - storage.write("weather.json", settings); + storage.write("weatherSetting.json", settings); } + E.showMenu({ "": { "title": "Weather" }, "Expiry": { @@ -19,6 +33,25 @@ }, onchange: (x) => save("expiry", x), }, + "Refresh Rate": { + value: "refresh" in settings ? settings.refresh : 0, + min: 0, + max: 24 * 3600000, + step: 15 * 60000, + format: (x) => { + if (x === 0) return "never"; + if (x < 3600000) return `${Math.floor(x / 60000)}m`; + if (x < 86400000) return `${Math.floor(x / 36000) / 100}h`; + }, + onchange: (x) => save("refresh", x), + }, + Forecast: { + value: "forecast" in settings ? settings.forecast : false, + onchange: () => { + settings.forecast = !settings.forecast; + save("forecast", settings.forecast); + }, + }, "Hide Widget": { value: "hide" in settings ? settings.hide : false, onchange: () => { @@ -26,6 +59,9 @@ save("hide", settings.hide); }, }, + "Force refresh": () => { + require("weather").updateWeather(true); + }, "< Back": back, }); }; diff --git a/apps/weather/widget.js b/apps/weather/widget.js index be0ca838fe..7e4d2c6dd6 100644 --- a/apps/weather/widget.js +++ b/apps/weather/widget.js @@ -6,7 +6,7 @@ let settings; function loadSettings() { - settings = require("Storage").readJSON("weather.json", 1) || {}; + settings = require("Storage").readJSON("weatherSetting.json", 1) || {}; } function setting(key) { From c58d5031576bdf892f8af7a9a23106d1afbbdd9c Mon Sep 17 00:00:00 2001 From: Rengyr Date: Sun, 29 Jun 2025 12:01:39 +0200 Subject: [PATCH 3/6] Weather: Add support for only extended weather data without forecast Android only support for now. With extended data we can parse feels like temperature with GB same as on iOS. --- apps/weather/README.md | 8 +++++--- apps/weather/lib.js | 37 +++++++++++++++++++++++++++---------- apps/weather/settings.js | 15 ++++++++++----- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/apps/weather/README.md b/apps/weather/README.md index 9c692c011c..66402b4bd4 100644 --- a/apps/weather/README.md +++ b/apps/weather/README.md @@ -77,7 +77,7 @@ Adds: * Expiration time span can be set after which the local weather data is considered as invalid * Automatic weather data request interval can be set (weather data are pushed to Bangle automatically, but this can help in cases when it fails) (requires Gadgetbridge v0.86+) -* Forecast weather data can be enabled (this requires other App to use the data, Weather App itself doesn't show the forecast data) (requires Gadgetbridge v0.86+) +* Extended or forecast weather data can be enabled (this requires other App to use this data, Weather App itself doesn't show the forecast data) (requires Gadgetbridge v0.86+) * Widget can be hidden * To change the units for wind speed, you can install the [`Languages app`](https://banglejs.com/apps/?id=locale) which allows you to choose the units used for speed/distance/temperature and so on. @@ -89,15 +89,17 @@ allows you to choose the units used for speed/distance/temperature and so on. ## Weather App API +Note: except `getWeather()` and `get()` it is android only for now + Weather App can provide weather and forecast data to other Apps. -* Get weather data without forecast: +* Get weather data without forecast/extended: ```javascript const weather = require("weather"); weatherData = weather.getWeather(false); // or weather.get() ``` -* Get weather data with forecast (needs forecast enabled in settings): +* Get weather data with forecast/extended (needs forecast/extended enabled in settings): ```javascript const weather = require("weather"); weatherData = weather.getWeather(true); diff --git a/apps/weather/lib.js b/apps/weather/lib.js index 604e76fca9..1f854fe0cc 100644 --- a/apps/weather/lib.js +++ b/apps/weather/lib.js @@ -61,13 +61,13 @@ function update(weatherEvent) { storage.write("weather.json", json); exports.emit("update", weather); - // Request forecast if supported by GadgetBridge and set in settings - if (weatherEvent.v != null && (weatherSetting.forecast ?? false)) { + // Request extended/forecast if supported by Weather Provider and set in settings + if (weatherEvent.v != null && (weatherSetting.dataType ?? "basic") !== "basic") { updateWeather(true); } - // Either GadgetBridge doesn't support v2 and/or we don't need forecast, so we use this event for refresh scheduling - if (weatherEvent.v == null || (weatherSetting.forecast ?? false) === false) { + // Either Weather Provider doesn't support v2 and/or we don't need extended/forecast, so we use this event for refresh scheduling + if (weatherEvent.v == null || (weatherSetting.dataType ?? "basic") === "basic") { weatherSetting.time = Date.now(); storage.write("weatherSetting.json", weatherSetting); @@ -93,6 +93,12 @@ function update(weatherEvent) { // Store simpler weather for apps that doesn't need forecast or backward compatibility const weather = downgradeWeatherV2(weather2); storage.write("weather.json", weather); + exports.emit("update", weather); + } else if (weather1.weather != null && weather1.weather.feels === undefined) { + // Grab feels like temperature as we have it in v2 + weather1.weather.feels = decodeWeatherV2FeelsLike(weatherEvent); + storage.write("weather.json", weather); + exports.emit("update", weather); } cloned = undefined; // Clear memory @@ -111,15 +117,15 @@ function updateWeather(force) { // More than 5 minutes if (force || Date.now() - lastFetch >= 5 * 60 * 1000) { - Bluetooth.println(""); - Bluetooth.println(JSON.stringify({ t: "weather", v: 2, f: settings.forecast ?? false })); + Bluetooth.println(""); // This empty line is important for correct communication with Weather Provider + Bluetooth.println(JSON.stringify({ t: "weather", v: 2, f: settings.dataType === "forecast" })); } } -function getWeather(forecast) { +function getWeather(extended) { const weatherSetting = storage.readJSON("weatherSetting.json") || {}; - if (forecast === false || !(weatherSetting.forecast ?? false)) { + if (extended === false || (weatherSetting.dataType ?? "basic") === "basic") { // biome-ignore lint/complexity/useOptionalChain: not supported by Espruino return (storage.readJSON("weather.json") ?? {}).weather; } else { @@ -169,7 +175,7 @@ function decodeWeatherV2(jsonData, canDestroyArgument, parseForecast) { return { t: "weather2", v: 2, time: time }; } - // This needs to be kept in sync with GadgetBridge + // This needs to be kept in sync with Weather Provider const weatherCodes = [ [200, 201, 202, 210, 211, 212, 221, 230, 231, 232], [300, 301, 302, 310, 311, 312, 313, 314, 321], @@ -214,7 +220,7 @@ function decodeWeatherV2(jsonData, canDestroyArgument, parseForecast) { moonrise: dataView.getUint32(27, true), moonset: dataView.getUint32(31, true), moonphase: dataView.getUint16(35, true), - feel: dataView.getInt8(37, true), + feels: dataView.getInt8(37, true), }; weather.wrose = windDirection(weather.wdir); @@ -256,6 +262,16 @@ function decodeWeatherV2(jsonData, canDestroyArgument, parseForecast) { return weather; } +function decodeWeatherV2FeelsLike(jsonData) { + if (jsonData == null || jsonData.d == null) { + return undefined; + } + + const buffer = E.toArrayBuffer(atob(jsonData.d)); + + return new DataView(buffer).getInt8(37, true); +} + function downgradeWeatherV2(weather2) { const json = { t: "weather" }; @@ -274,6 +290,7 @@ function downgradeWeatherV2(weather2) { wdir: weather2.wdir, wrose: weather2.wrose, loc: weather2.loc, + feels: weather2.feels, }; return json; diff --git a/apps/weather/settings.js b/apps/weather/settings.js index f0b43b678f..443ef898fb 100644 --- a/apps/weather/settings.js +++ b/apps/weather/settings.js @@ -19,6 +19,8 @@ storage.write("weatherSetting.json", settings); } + const DATA_TYPE = ["basic", "extended", "forecast"]; + E.showMenu({ "": { "title": "Weather" }, "Expiry": { @@ -45,11 +47,14 @@ }, onchange: (x) => save("refresh", x), }, - Forecast: { - value: "forecast" in settings ? settings.forecast : false, - onchange: () => { - settings.forecast = !settings.forecast; - save("forecast", settings.forecast); + "Data type": { + value: DATA_TYPE.indexOf(settings.dataType ?? "basic"), + format: (v) => DATA_TYPE[v], + min: 0, + max: DATA_TYPE.length - 1, + onchange: (v) => { + settings.dataType = DATA_TYPE[v]; + save("dataType", settings.dataType); }, }, "Hide Widget": { From c94e53e6aab41ef98a2dd3a27a31a22954f19f55 Mon Sep 17 00:00:00 2001 From: Rengyr Date: Mon, 30 Jun 2025 19:48:46 +0200 Subject: [PATCH 4/6] Weather: Change android only settings to show only when Android App is installed --- apps/weather/settings.js | 47 ++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/apps/weather/settings.js b/apps/weather/settings.js index 443ef898fb..263d6a18b5 100644 --- a/apps/weather/settings.js +++ b/apps/weather/settings.js @@ -21,7 +21,7 @@ const DATA_TYPE = ["basic", "extended", "forecast"]; - E.showMenu({ + menuItems = { "": { "title": "Weather" }, "Expiry": { value: "expiry" in settings ? settings.expiry : 2 * 3600000, @@ -35,7 +35,26 @@ }, onchange: (x) => save("expiry", x), }, - "Refresh Rate": { + "Hide Widget": { + value: "hide" in settings ? settings.hide : false, + onchange: () => { + settings.hide = !settings.hide; + save("hide", settings.hide); + }, + }, + "< Back": back, + }; + + // Add android only settings + let android = false; + try { + if (require("android") != null) { + android = true; + } + } catch (_) {} + + if (android) { + menuItems["Refresh Rate"] = { value: "refresh" in settings ? settings.refresh : 0, min: 0, max: 24 * 3600000, @@ -46,8 +65,9 @@ if (x < 86400000) return `${Math.floor(x / 36000) / 100}h`; }, onchange: (x) => save("refresh", x), - }, - "Data type": { + }; + + menuItems["Data type"] = { value: DATA_TYPE.indexOf(settings.dataType ?? "basic"), format: (v) => DATA_TYPE[v], min: 0, @@ -56,17 +76,12 @@ settings.dataType = DATA_TYPE[v]; save("dataType", settings.dataType); }, - }, - "Hide Widget": { - value: "hide" in settings ? settings.hide : false, - onchange: () => { - settings.hide = !settings.hide; - save("hide", settings.hide); - }, - }, - "Force refresh": () => { + }; + + menuItems["Force refresh"] = () => { require("weather").updateWeather(true); - }, - "< Back": back, - }); + }; + } + + E.showMenu(menuItems); }; From 6f9b5ad0b4bd348a17a243982ef681aabb606e62 Mon Sep 17 00:00:00 2001 From: Rengyr Date: Fri, 15 Aug 2025 16:37:00 +0200 Subject: [PATCH 5/6] Weather: Fix linting warnings --- apps/weather/lib.js | 4 ++-- apps/weather/settings.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/weather/lib.js b/apps/weather/lib.js index 1f854fe0cc..23bc2323c3 100644 --- a/apps/weather/lib.js +++ b/apps/weather/lib.js @@ -97,8 +97,8 @@ function update(weatherEvent) { } else if (weather1.weather != null && weather1.weather.feels === undefined) { // Grab feels like temperature as we have it in v2 weather1.weather.feels = decodeWeatherV2FeelsLike(weatherEvent); - storage.write("weather.json", weather); - exports.emit("update", weather); + storage.write("weather.json", weather1); + exports.emit("update", weather1); } cloned = undefined; // Clear memory diff --git a/apps/weather/settings.js b/apps/weather/settings.js index 263d6a18b5..07b13c73a6 100644 --- a/apps/weather/settings.js +++ b/apps/weather/settings.js @@ -1,4 +1,4 @@ -(back) => { +(function (back) { const storage = require("Storage"); let settings = storage.readJSON("weatherSetting.json", 1); @@ -21,7 +21,7 @@ const DATA_TYPE = ["basic", "extended", "forecast"]; - menuItems = { + let menuItems = { "": { "title": "Weather" }, "Expiry": { value: "expiry" in settings ? settings.expiry : 2 * 3600000, @@ -84,4 +84,4 @@ } E.showMenu(menuItems); -}; +}) From 6e002702875e2ef32afb05f324a42a9a0126f5ed Mon Sep 17 00:00:00 2001 From: Rengyr Date: Sat, 16 Aug 2025 22:36:47 +0200 Subject: [PATCH 6/6] Weather: Fix 'feels like' temp being in wrong units --- apps/weather/lib.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/weather/lib.js b/apps/weather/lib.js index 23bc2323c3..81ab852fc2 100644 --- a/apps/weather/lib.js +++ b/apps/weather/lib.js @@ -96,7 +96,7 @@ function update(weatherEvent) { exports.emit("update", weather); } else if (weather1.weather != null && weather1.weather.feels === undefined) { // Grab feels like temperature as we have it in v2 - weather1.weather.feels = decodeWeatherV2FeelsLike(weatherEvent); + weather1.weather.feels = decodeWeatherV2FeelsLike(weatherEvent) + 273; storage.write("weather.json", weather1); exports.emit("update", weather1); } @@ -290,7 +290,7 @@ function downgradeWeatherV2(weather2) { wdir: weather2.wdir, wrose: weather2.wrose, loc: weather2.loc, - feels: weather2.feels, + feels: weather2.feels + 273, }; return json;