feat(signage): the weather all the way: a week, the next hours, feels like, humidity, wind, rain chance, sunrise / sunset, UV, in words; row, column, card, list of days or hourly layouts

services/weather.py asks Open-Meteo for 7 days, the next 24 hours and the details
(mph for Fahrenheit); older answers without them still read. The widget's layout,
the details it adds and the place's name; up to 7 days. Plan 6R.18, F-116.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 15:07:03 +02:00
co-authored by Claude Opus 5.5
parent 673113aff7
commit 84c2d5b2d8
10 changed files with 301 additions and 43 deletions
@@ -104,6 +104,8 @@ def test_the_weather_shows_with_internet_and_hides_without(client, owner_h, tv,
assert ("signage.changed", [tv["id"]]) in sent
w = client.get("/api/signage/screen", headers=tv["h"]).json()["venue"]["weather"]
assert w["place"] == "Kalavryta" and w["code"] == 2 and [d["max"] for d in w["days"]] == [19.0, 16.5] and w["units"] == "celsius"
# 6R.18: an answer without the detailed fields still reads (they are None)
assert w["feels_like"] is None and w["days"][0]["sunrise"] is None and w["hours"] == [] and w["wind_unit"] == "km/h"
# the internet goes: the last forecast stays while it is fresh, then the widget hides
internet["up"] = False
sent.clear()
@@ -128,3 +130,28 @@ def test_who_may(client, make_user, login):
waiter = login(make_user(role="waiter"))
assert client.put("/api/signage/message", headers=waiter, json={"text": "x"}).status_code == 403
assert client.get("/api/signage/weather", headers=waiter).status_code == 403
def test_the_detailed_weather(monkeypatch):
"""6R.18: humidity, feels like, wind, rain chance, sunrise / sunset, UV and the next 24 hours."""
import asyncio
import httpx
from services import weather
hours = [f"2026-11-17T{h:02d}:00" for h in range(24)] + [f"2026-11-18T{h:02d}:00" for h in range(24)]
answer = {"current": {"time": "2026-11-17T12:15", "temperature_2m": 17.4, "weather_code": 2, "is_day": 1, "apparent_temperature": 15.9,
"relative_humidity_2m": 62, "wind_speed_10m": 12.3, "wind_direction_10m": 200, "precipitation": 0},
"daily": {"time": ["2026-11-17", "2026-11-18"], "temperature_2m_max": [19.0, 16.5], "temperature_2m_min": [9.1, 8.0],
"weather_code": [2, 61], "precipitation_probability_max": [10, 80], "wind_speed_10m_max": [20, 35], "uv_index_max": [3.2, 1.0],
"sunrise": ["2026-11-17T07:12", "2026-11-18T07:13"], "sunset": ["2026-11-17T17:08", "2026-11-18T17:07"]},
"hourly": {"time": hours, "temperature_2m": list(range(48)), "weather_code": [0] * 48, "precipitation_probability": [5] * 48, "is_day": [1] * 48}}
seen = {}
def handler(req):
seen.update(dict(req.url.params))
return httpx.Response(200, json=answer)
c = httpx.AsyncClient(transport=httpx.MockTransport(handler))
w = asyncio.run(weather.fetch({"name": "X", "latitude": 1, "longitude": 2, "units": "fahrenheit"}, c))
assert seen["forecast_days"] == "7" and seen["wind_speed_unit"] == "mph" and "hourly" in seen
assert w["feels_like"] == 15.9 and w["humidity"] == 62 and w["wind"] == 12.3 and w["wind_unit"] == "mph"
assert w["days"][1] == {"date": "2026-11-18", "max": 16.5, "min": 8.0, "code": 61, "rain": 80, "wind": 35, "uv": 1.0, "sunrise": "07:13", "sunset": "17:07"}
assert len(w["hours"]) == 24 and w["hours"][0]["time"] == "12:00" and w["hours"][0]["temp"] == 12 and w["hours"][-1]["time"] == "11:00"