Skip to content

Commit d501458

Browse files
authored
Merge pull request #3910 from Rengyr/master
Weather: Add v2 weather parsing in Weather App (forecast support)
2 parents bc375c5 + 6e00270 commit d501458

File tree

8 files changed

+514
-159
lines changed

8 files changed

+514
-159
lines changed

apps/weather/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@
2626
0.27: Add UV index display
2727
0.28: Fix UV positioning, hide when 0
2828
0.29: Add feels-like temperature data and clock_info
29+
0.30: Refactor code to more modern javascript style
30+
Split settings and weather data into two files in storage
31+
Add support for new version of weather data and forecast from GadgetBridge (requires version 0.86.0 or higher)
32+
Add support to automatically fetch weather at time interval defined in settings (requires GadgetBridge version 0.86.0 or higher)
33+
Add button to settings to force fetch weather data (requires GadgetBridge version 0.86.0 or higher)
34+
Add new API to get weather from Weather App for other Apps

apps/weather/README.md

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
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.
44

55
It adds a widget with a weather pictogram and the temperature.
6-
It also adds a ClockInfo list to Bangle.js.
6+
It also adds a ClockInfo list to Bangle.js.
77
You can view the full report through the app:
88

99
![Screenshot](screenshot.png)
@@ -12,35 +12,35 @@ You can view the full report through the app:
1212

1313
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.
1414

15-
1615
## Android Setup
1716

18-
1. Install [Gadgetbridge for Android](https://f-droid.org/packages/nodomain.freeyourgadget.gadgetbridge/) on your phone.
19-
2. Set up [Gadgetbridge weather reporting](https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Weather).
20-
21-
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
22-
to `com.espruino.gadgetbridge.banglejs` in the settings of the weather app (`settings -> gadgetbridge support -> package name`).
17+
1. Install [Gadgetbridge for Android](https://f-droid.org/packages/nodomain.freeyourgadget.gadgetbridge/) on your phone
18+
2. Set up [Gadgetbridge weather reporting](https://gadgetbridge.org/basics/features/weather/)
2319

2420
### Android Weather Apps
2521

26-
There are two weather apps for Android that can connect with Gadgetbridge:
22+
There are multiple weather apps for Android that can connect with Gadgetbridge:
2723

2824
* Tiny Weather Forecast Germany
29-
* F-Droid - https://f-droid.org/en/packages/de.kaffeemitkoffein.tinyweatherforecastgermany/
30-
* Source code - https://codeberg.org/Starfish/TinyWeatherForecastGermany
31-
25+
* F-Droid - https://f-droid.org/en/packages/de.kaffeemitkoffein.tinyweatherforecastgermany/
26+
* Source code - https://codeberg.org/Starfish/TinyWeatherForecastGermany
27+
3228
* QuickWeather
33-
* F-Droid - https://f-droid.org/en/packages/com.ominous.quickweather/
34-
* Google Play - https://play.google.com/store/apps/details?id=com.ominous.quickweather
35-
* Source code - https://github.com/TylerWilliamson/QuickWeather
36-
29+
* F-Droid - https://f-droid.org/en/packages/com.ominous.quickweather/
30+
* Google Play - https://play.google.com/store/apps/details?id=com.ominous.quickweather
31+
* Source code - https://github.com/TylerWilliamson/QuickWeather
32+
33+
* Breezy Weather
34+
* F-Droid - https://f-droid.org/en/packages/org.breezyweather/
35+
* Source code - https://github.com/breezy-weather/breezy-weather
36+
3737
### Tiny Weather Forecast Germany
3838

3939
Even though Tiny Weather Forecast Germany is made for Germany, it can be used around the world. To do this:
40-
40+
4141
1. Tap on the three dots in the top right hand corner and go to settings
4242
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.
43-
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".
43+
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".
4444
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.
4545

4646
### QuickWeather
@@ -51,9 +51,17 @@ If you're using OpenWeatherMap you will need the "One Call By Call" plan, which
5151

5252
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.
5353

54+
### Breezy Weather
55+
56+
Enabling connection to Gadgetbridge:
57+
58+
1. Tap on the three dots in the top right hand corner and go to settings
59+
2. Find "Widgets & Live wallpaper" settings
60+
3. Under "Data sharing" tap on "Send Gadgetbridge data" and enable for Gadgetbridge flavor you are using
61+
5462
### Weather Notification
5563

56-
**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.
64+
**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.
5765

5866
## Clock Infos
5967

@@ -67,7 +75,9 @@ Adds:
6775

6876
## Settings
6977

70-
* Expiration timespan can be set after which the local weather data is considered as invalid
78+
* Expiration time span can be set after which the local weather data is considered as invalid
79+
* 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+)
80+
* 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+)
7181
* Widget can be hidden
7282
* To change the units for wind speed, you can install the [`Languages app`](https://banglejs.com/apps/?id=locale) which
7383
allows you to choose the units used for speed/distance/temperature and so on.
@@ -76,3 +86,44 @@ allows you to choose the units used for speed/distance/temperature and so on.
7686

7787
* BTN2: opens the launcher (Bangle.js 1)
7888
* BTN: opens the launcher (Bangle.js 2)
89+
90+
## Weather App API
91+
92+
Note: except `getWeather()` and `get()` it is android only for now
93+
94+
Weather App can provide weather and forecast data to other Apps.
95+
96+
* Get weather data without forecast/extended:
97+
```javascript
98+
const weather = require("weather");
99+
weatherData = weather.getWeather(false); // or weather.get()
100+
```
101+
102+
* Get weather data with forecast/extended (needs forecast/extended enabled in settings):
103+
```javascript
104+
const weather = require("weather");
105+
weatherData = weather.getWeather(true);
106+
```
107+
108+
* Fetch new data from Gadgetbridge:
109+
```javascript
110+
const weather = require("weather");
111+
weather.updateWeather(false); // Can set to true if we want to ignore debounce
112+
```
113+
114+
* React to updated weather data:
115+
```javascript
116+
const weather = require("weather");
117+
118+
// For weather data without forecast
119+
weather.on("update", () => {
120+
currentData = weather.getWeather(false);
121+
// console.log(currentData);
122+
}
123+
124+
// For weather data with forecast
125+
weather.on("update2", () => {
126+
currentData = weather.getWeather(true);
127+
// console.log(currentData);
128+
}
129+
```

apps/weather/app.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [
1616
render: l => {
1717
if (!current || current.uv === undefined) return;
1818
const uv = Math.min(parseInt(current.uv), 11); // Cap at 11
19-
19+
2020
// UV color thresholds: [max_value, color] based on WHO standards
2121
const colors = [[2,"#0F0"], [5,"#FF0"], [7,"#F80"], [10,"#F00"], [11,"#F0F"]];
2222
const color = colors.find(c => uv <= c[0])[1];
23-
23+
2424
// Setup and measure label
2525
g.setFont("6x8").setFontAlign(-1, 0);
2626
const label = "UV: ";
2727
const labelW = g.stringWidth(label);
28-
28+
2929
// Calculate centered position (4px block + 1px spacing) * blocks - last spacing
3030
const totalW = labelW + uv * 5 - (uv > 0 ? 1 : 0);
3131
const x = l.x + (l.w - totalW) / 2;
3232
const y = l.y + l.h+6;
33-
33+
3434
// Draw label
3535
g.setColor(g.theme.fg).drawString(label, x, y);
36-
36+
3737
// Draw UV blocks
3838
g.setColor(color);
3939
for (let i = 0; i < uv; i++) {
@@ -58,7 +58,7 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [
5858
{type: "txt", font: "6x8", pad: 2, halign: 1, label: /*LANG*/"Hum:"},
5959
{type: "txt", font: "9%", pad: 2, halign: 1, id: "hum", label: "000%"},
6060
]},
61-
61+
6262
{filly: 1},
6363
{type: "txt", font: "6x8", pad: 2, halign: -1, label: /*LANG*/"Wind"},
6464
{type: "h", halign: -1, c: [
@@ -79,7 +79,7 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [
7979
]}, {lazy: true});
8080

8181
function formatDuration(millis) {
82-
let pluralize = (n, w) => n + " " + w + (n == 1 ? "" : "s");
82+
let pluralize = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
8383
if (millis < 60000) return /*LANG*/"< 1 minute";
8484
if (millis < 3600000) return pluralize(Math.floor(millis/60000), /*LANG*/"minute");
8585
if (millis < 86400000) return pluralize(Math.floor(millis/3600000), /*LANG*/"hour");
@@ -98,11 +98,11 @@ function draw() {
9898
}else{
9999
layout.feelslike.label = feelsLikeTemp[1]+feelsLikeTemp[2];
100100
}
101-
102-
layout.hum.label = current.hum+"%";
101+
102+
layout.hum.label = `${current.hum}%`;
103103
const wind = locale.speed(current.wind).match(/^(\D*\d*)(.*)$/);
104104
layout.wind.label = wind[1];
105-
layout.windUnit.label = wind[2] + " " + (current.wrose||'').toUpperCase();
105+
layout.windUnit.label = `${wind[2]} ${(current.wrose||'').toUpperCase()}`;
106106
layout.cond.label = current.txt.charAt(0).toUpperCase()+(current.txt||'').slice(1);
107107
layout.loc.label = current.loc;
108108
layout.updateTime.label = `${formatDuration(Date.now() - current.time)} ago`; // How to autotranslate this and similar?

apps/weather/clkinfo.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
(function() {
1+
(() => {
32
var weather;
43
var weatherLib = require("weather");
54

@@ -8,9 +7,9 @@
87
if(weather){
98
weather.temp = require("locale").temp(weather.temp-273.15);
109
weather.feels = require("locale").temp(weather.feels-273.15);
11-
weather.hum = weather.hum + "%";
10+
weather.hum = `${weather.hum}%`;
1211
weather.wind = require("locale").speed(weather.wind).match(/^(\D*\d*)(.*)$/);
13-
weather.wind = Math.round(weather.wind[1]) + "kph";
12+
weather.wind = `${Math.round(weather.wind[1])}kph`;
1413
} else {
1514
weather = {
1615
temp: "?",

0 commit comments

Comments
 (0)