diff options
| author | Tait Berlette <54515877+taitberlette@users.noreply.github.com> | 2021-08-18 17:13:49 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel.thompson@linaro.org> | 2021-08-23 19:09:02 (GMT) |
| commit | dc40430faaa5d9911e2dd46c414d790e28560cf8 (patch) | |
| tree | b0a18764d0835157111f123ec8f4b2e6007b421b /wasp/apps/weather.py | |
| parent | a28a2cd7f462a217ab5598853835e806c83967f7 (diff) | |
apps: Fixed weather app with GadgetBridge.
When I created the weather app I didn't have GadgetBridge installed, so I tried to follow the protocol on the [espurino website](https://www.espruino.com/Gadgetbridge), but it wasn't very helpful and I made some mistakes. This commit should fix these mistakes to stop the weather app from crashing, and so it displays the correct values. I have also added a new settings option called "Units", where apps can see what units the user would prefer (metric/imperial).
Signed-off-by: Tait Berlette <54515877+taitberlette@users.noreply.github.com>
Diffstat (limited to 'wasp/apps/weather.py')
| -rw-r--r-- | wasp/apps/weather.py | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/wasp/apps/weather.py b/wasp/apps/weather.py index 2e44da4..55c4809 100644 --- a/wasp/apps/weather.py +++ b/wasp/apps/weather.py @@ -50,10 +50,10 @@ class WeatherApp(object): ICON = icon def __init__(self): - self._temp = '' - self._hum = '' + self._temp = -1 + self._hum = 0 self._txt = '' - self._wind = '' + self._wind = 0 self._loc = '' self._temp_changed = True self._hum_changed = True @@ -136,16 +136,32 @@ class WeatherApp(object): def _draw(self): """Redraw the updated zones.""" - if self._temp_changed: - self._draw_label(self._temp, 54, 36) - if self._hum_changed: - self._draw_label("Humidity: "+self._hum, 160) - if self._txt_changed: - self._draw_label(self._txt, 12) - if self._wind_changed: - self._draw_label("Wind: "+self._wind, 120) - if self._loc_changed: - self._draw_label(self._loc, 200) + draw = wasp.watch.drawable + if self._temp != -1: + units = wasp.system.units + temp = self._temp - 273.15 + wind = self._wind + wind_units = "km/h" + if units == "Imperial": + temp = (temp * 1.8) + 32 + wind = wind / 1.609 + wind_units = "mph" + temp = round(temp) + wind = round(wind) + if self._temp_changed: + self._draw_label(str(temp), 54, 36) + if self._hum_changed: + self._draw_label("Humidity: {}%".format(self._hum), 160) + if self._txt_changed: + self._draw_label(self._txt, 12) + if self._wind_changed: + self._draw_label("Wind: {}{}".format(wind, wind_units), 120) + if self._loc_changed: + self._draw_label(self._loc, 200) + else: + if self._temp_changed: + draw.fill() + self._draw_label("No weather data.", 120) def _draw_label(self, label, pos, size = 24): """Redraw label info""" |
