Week ahead in the weather strip, reverse LCD at night

The weekday strip now shows today and the next six days (icon, max, min),
the current temperature and feels-like sit next to the clock, and the rain
graph spans the full width with the hour under every bar. From sunset to
sunrise the whole frame, seconds patch included, is drawn as a reverse LCD.
The rain label is now spelled DÉŠŤ.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rickzkmandClaude Opus 5.5 committed 2026-10-28 22:40:34 +01:00
1 parent 45508b1b68
commit 6c9a1420d2
10 files changed
+341 -122

No files matched your search

+1 -1
View File
@@ -1 +1 @@
{"latitude":49.23005,"longitude":17.657297,"generationtime_ms":0.3495216369628906,"utc_offset_seconds":7200,"timezone":"Europe/Prague","timezone_abbreviation":"GMT+2","elevation":221.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C","weather_code":"wmo code"},"current":{"time":"2026-10-22T12:45","interval":900,"temperature_2m":10.2,"weather_code":61},"hourly_units":{"time":"iso8601","precipitation_probability":"%","precipitation":"mm"},"hourly":{"time":["2026-10-22T00:00","2026-10-22T01:00","2026-10-22T02:00","2026-10-22T03:00","2026-10-22T04:00","2026-10-22T05:00","2026-10-22T06:00","2026-10-22T07:00","2026-10-22T08:00","2026-10-22T09:00","2026-10-22T10:00","2026-10-22T11:00","2026-10-22T12:00","2026-10-22T13:00","2026-10-22T14:00","2026-10-22T15:00","2026-10-22T16:00","2026-10-22T17:00","2026-10-22T18:00","2026-10-22T19:00","2026-10-22T20:00","2026-10-22T21:00","2026-10-22T22:00","2026-10-22T23:00","2026-10-23T00:00","2026-10-23T01:00","2026-10-23T02:00","2026-10-23T03:00","2026-10-23T04:00","2026-10-23T05:00","2026-10-23T06:00","2026-10-23T07:00","2026-10-23T08:00","2026-10-23T09:00","2026-10-23T10:00","2026-10-23T11:00","2026-10-23T12:00","2026-10-23T13:00","2026-10-23T14:00","2026-10-23T15:00","2026-10-23T16:00","2026-10-23T17:00","2026-10-23T18:00","2026-10-23T19:00","2026-10-23T20:00","2026-10-23T21:00","2026-10-23T22:00","2026-10-23T23:00"],"precipitation_probability":[93,98,100,100,100,100,100,100,100,100,100,98,93,98,63,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,5,3,0],"precipitation":[0.40,1.80,2.50,3.80,2.00,2.20,2.30,1.40,2.60,3.50,1.80,1.00,0.40,0.50,0.40,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00]},"daily_units":{"time":"iso8601","temperature_2m_max":"°C","temperature_2m_min":"°C"},"daily":{"time":["2026-10-22","2026-10-23"],"temperature_2m_max":[15.0,14.3],"temperature_2m_min":[6.0,2.2]}}
{"latitude":49.23005,"longitude":17.657297,"generationtime_ms":0.3495216369628906,"utc_offset_seconds":7200,"timezone":"Europe/Prague","timezone_abbreviation":"GMT+2","elevation":221.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C","weather_code":"wmo code","apparent_temperature":"°C"},"current":{"time":"2026-10-22T12:45","interval":900,"temperature_2m":10.2,"weather_code":61,"apparent_temperature":8.1},"hourly_units":{"time":"iso8601","precipitation_probability":"%","precipitation":"mm"},"hourly":{"time":["2026-10-22T00:00","2026-10-22T01:00","2026-10-22T02:00","2026-10-22T03:00","2026-10-22T04:00","2026-10-22T05:00","2026-10-22T06:00","2026-10-22T07:00","2026-10-22T08:00","2026-10-22T09:00","2026-10-22T10:00","2026-10-22T11:00","2026-10-22T12:00","2026-10-22T13:00","2026-10-22T14:00","2026-10-22T15:00","2026-10-22T16:00","2026-10-22T17:00","2026-10-22T18:00","2026-10-22T19:00","2026-10-22T20:00","2026-10-22T21:00","2026-10-22T22:00","2026-10-22T23:00","2026-10-23T00:00","2026-10-23T01:00","2026-10-23T02:00","2026-10-23T03:00","2026-10-23T04:00","2026-10-23T05:00","2026-10-23T06:00","2026-10-23T07:00","2026-10-23T08:00","2026-10-23T09:00","2026-10-23T10:00","2026-10-23T11:00","2026-10-23T12:00","2026-10-23T13:00","2026-10-23T14:00","2026-10-23T15:00","2026-10-23T16:00","2026-10-23T17:00","2026-10-23T18:00","2026-10-23T19:00","2026-10-23T20:00","2026-10-23T21:00","2026-10-23T22:00","2026-10-23T23:00"],"precipitation_probability":[93,98,100,100,100,100,100,100,100,100,100,98,93,98,63,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,5,3,0],"precipitation":[0.4,1.8,2.5,3.8,2.0,2.2,2.3,1.4,2.6,3.5,1.8,1.0,0.4,0.5,0.4,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]},"daily_units":{"time":"iso8601","weather_code":"wmo code","temperature_2m_max":"°C","temperature_2m_min":"°C","sunrise":"iso8601","sunset":"iso8601"},"daily":{"time":["2026-10-22","2026-10-23","2026-10-24","2026-10-25","2026-10-26","2026-10-27","2026-10-28"],"weather_code":[63,45,61,63,80,45,45],"temperature_2m_max":[15.0,14.3,12.1,10.2,11.2,10.0,11.5],"temperature_2m_min":[6.0,2.2,4.3,0.8,1.9,-0.2,-0.5],"sunrise":["2026-10-22T07:20","2026-10-23T07:22","2026-10-24T07:24","2026-10-25T06:25","2026-10-26T06:27","2026-10-27T06:28","2026-10-28T06:30"],"sunset":["2026-10-22T17:45","2026-10-23T17:44","2026-10-24T17:42","2026-10-25T16:40","2026-10-26T16:38","2026-10-27T16:36","2026-10-28T16:35"]}}
+19
View File
@@ -81,3 +81,22 @@ def test_tag_is_ink_box_and_returns_its_box():
x0, y0, x1, y1 = box
assert img.getpixel((x0 + 1, y0 + 1)) == INK
assert x1 > x0 and y1 > y0
def test_night_turns_background_dark_and_ink_light():
img = Image.new("RGB", (3, 1), BG)
img.putpixel((1, 0), INK)
img.putpixel((2, 0), GHOST)
bg, ink, ghost = (sum(lcdkit.night(img).getpixel((x, 0))) for x in range(3))
assert bg < 100 and ink > 450
# unlit segments stay faint: a little lighter than the background, nowhere near the ink
assert bg < ghost < (bg + ink) / 2
def test_night_keeps_antialiased_text_in_between():
mid = tuple((a + b) // 2 for a, b in zip(INK, BG))
img = Image.new("RGB", (3, 1), BG)
img.putpixel((1, 0), INK)
img.putpixel((2, 0), mid)
bg, ink, edge = (sum(lcdkit.night(img).getpixel((x, 0))) for x in range(3))
assert bg < edge < ink
+52 -5
View File
@@ -1,10 +1,10 @@
import copy
import json
from datetime import datetime
from datetime import date, datetime
from pathlib import Path
import weather_data
from weather_data import Icon, icon_for, parse_weather
from weather_data import Day, Icon, icon_for, parse_weather
FIXTURE = json.loads((Path(__file__).parent / "fixtures" / "open-meteo-zlin.json").read_text())
NOW = datetime(2026, 10, 22, 12, 45)
@@ -24,9 +24,34 @@ def test_parse_fixture_window():
assert (w.temp, w.code) == (10.2, 61)
def test_parse_today_max_min():
def test_parse_week_with_sunrise_and_sunset():
w = parse_weather(payload(), NOW)
assert (w.today_max, w.today_min) == (15.0, 6.0)
assert len(w.days) == 7
assert w.days[0] == Day(date(2026, 10, 22), 63, 15.0, 6.0,
datetime(2026, 10, 22, 7, 20), datetime(2026, 10, 22, 17, 45))
assert w.days[6] == Day(date(2026, 10, 28), 45, 11.5, -0.5,
datetime(2026, 10, 28, 6, 30), datetime(2026, 10, 28, 16, 35))
def test_parse_feels_like():
assert parse_weather(payload(), NOW).feels == 8.1
def test_null_day_entries_become_none():
p = payload()
p["daily"]["weather_code"][1] = None
p["daily"]["sunset"][1] = None
day = parse_weather(p, NOW).days[1]
assert (day.code, day.sunset) == (None, None)
assert day.sunrise == datetime(2026, 10, 23, 7, 22)
def test_short_daily_lists_give_none_not_errors():
p = payload()
p["daily"]["temperature_2m_min"] = p["daily"]["temperature_2m_min"][:3]
w = parse_weather(p, NOW)
assert len(w.days) == 7
assert (w.days[2].low, w.days[3].low) == (4.3, None)
def test_window_runs_into_tomorrow_late_in_the_day():
@@ -74,7 +99,7 @@ def test_missing_current_gives_none_temp():
def test_missing_sections_do_not_raise():
w = parse_weather({}, NOW)
assert (w.temp, w.today_max, w.hours) == (None, None, ())
assert (w.temp, w.feels, w.days, w.hours) == (None, None, (), ())
def test_fetch_passes_coordinates():
@@ -99,3 +124,25 @@ def test_fetch_passes_coordinates():
assert params["timezone"] == "Europe/Prague"
assert timeout == 10
assert len(w.hours) == 12
assert len(w.days) == 7
def test_fetch_asks_for_a_week_with_sun_times_and_feels_like():
seen = {}
class Response:
def raise_for_status(self):
pass
def json(self):
return payload()
def fake_get(url, params=None, timeout=None):
seen.update(params)
return Response()
weather_data.fetch_weather(NOW, get=fake_get)
assert seen["forecast_days"] >= 7
assert set(seen["daily"].split(",")) >= {"weather_code", "temperature_2m_max", "temperature_2m_min",
"sunrise", "sunset"}
assert "apparent_temperature" in seen["current"].split(",")
+127 -37
View File
@@ -1,15 +1,18 @@
from datetime import datetime
from datetime import date, datetime, time, timedelta
import numpy as np
from PIL import ImageChops
from lcdkit import INK
from lcdkit import BG, INK
from tests.helpers import count_colour
from view import Patch
from weather_data import Hour, Weather
from weather_view import WeatherView
from weather_data import Day, Hour, Weather
from weather_view import WeatherView, is_night
NOW = datetime(2026, 10, 22, 12, 45, 8) # a Thursday
CODES = (63, 45, 61, 3, 80, 0, 71)
CELL = 65 # width of one day in the forecast strip
BAR_X, BAR_PITCH, BAR_W = 22, 37, 26
class StubPoller:
@@ -27,9 +30,19 @@ class StubPoller:
pass
def weather(temp=14.2, rain=(0, 0, 10, 20, 40, 70, 60, 50, 30, 20, 10, 0), code=2):
def day(d: date, sunrise=time(7, 20), sunset=time(17, 45)) -> Day:
"""A forecast day whose values depend only on its date."""
return Day(d, CODES[d.toordinal() % 7], float(5 + d.day % 10), float(d.day % 5),
datetime.combine(d, sunrise), datetime.combine(d, sunset))
def week(start=date(2026, 10, 22), n=7):
return tuple(day(start + timedelta(days=i)) for i in range(n))
def weather(temp=14.2, rain=(0, 0, 10, 20, 40, 70, 60, 50, 30, 20, 10, 0), code=2, days=None):
hours = tuple(Hour(datetime(2026, 10, 22, 12 + i, 0), p, 0.2) for i, p in enumerate(rain))
return Weather(temp=temp, code=code, today_max=16.0, today_min=7.0, hours=hours)
return Weather(temp=temp, feels=12.1, code=code, days=week() if days is None else days, hours=hours)
def view(**kw):
@@ -45,6 +58,20 @@ def ink_bbox(img, box):
return (box[0] + xs.min(), box[1] + ys.min(), box[0] + xs.max(), box[1] + ys.max())
def icon_box(i):
cx = 12 + i * CELL + CELL // 2
return (cx - 16, 34, cx + 16, 68)
def hour_label_box(i):
x = BAR_X + i * BAR_PITCH
return (x, 290, x + BAR_W, 304)
def same(a, b):
return ImageChops.difference(a.convert("RGB"), b.convert("RGB")).getbbox() is None
def test_render_size_is_480x320():
assert view(value=weather()).render(NOW).size == (480, 320)
@@ -77,20 +104,20 @@ def test_patch_matches_full_render_region():
assert isinstance(patch, Patch)
full = v.render(NOW)
region = full.crop((patch.x, patch.y, patch.x + patch.image.width, patch.y + patch.image.height))
assert ImageChops.difference(region.convert("RGB"), patch.image.convert("RGB")).getbbox() is None
assert same(region, patch.image)
def test_patch_changes_with_the_second():
v = view(value=weather())
a = v.patch(datetime(2026, 10, 22, 12, 45, 8)).image
b = v.patch(datetime(2026, 10, 22, 12, 45, 9)).image
assert ImageChops.difference(a, b).getbbox() is not None
assert not same(a, b)
def test_no_weather_renders_without_error():
img = view(value=None, version=0, age=None).render(NOW)
assert img.size == (480, 320)
# weekday strip, clock and dashes are still drawn
# day names, clock and dashes are still drawn
assert count_colour(img, INK) > 1000
@@ -99,35 +126,54 @@ def test_stale_tag_only_when_old():
old = view(value=weather(), age=7200.0).render(NOW)
bbox = ImageChops.difference(fresh.convert("RGB"), old.convert("RGB")).getbbox()
assert bbox is not None
assert bbox[0] >= 20 and bbox[1] >= 160 and bbox[2] <= 204 and bbox[3] <= 186
assert bbox[0] >= 20 and bbox[1] >= 200 and bbox[2] <= 300 and bbox[3] <= 226 # on the rain header line
def test_hundred_percent_fits():
rain = (100,) * 12
img = view(value=weather(rain=rain)).render(NOW)
box = ink_bbox(img, (14, 262, 204, 312))
assert box is not None and box[2] < 200
def test_today_is_the_first_day_and_inverted():
img = view(value=weather()).render(NOW)
assert img.getpixel((12 + 5, 14)) == INK
assert img.getpixel((12 + CELL + 5, 14)) != INK
def test_negative_temp_fits_and_draws_minus():
def test_days_before_today_are_skipped():
# just after midnight the last fetch still starts with yesterday
from_yesterday = view(value=weather(days=week(start=date(2026, 10, 21)))).render(NOW)
from_today = view(value=weather(days=week(start=date(2026, 10, 22), n=6))).render(NOW)
assert same(from_yesterday, from_today)
def test_only_days_with_a_forecast_get_an_icon():
img = view(value=weather(days=week(n=3))).render(NOW)
for i in range(3):
assert ink_bbox(img, icon_box(i)) is not None, i
for i in range(3, 7):
assert ink_bbox(img, icon_box(i)) is None, i
def test_every_bar_has_its_hour_label():
img = view(value=weather()).render(NOW)
for i in range(12):
assert ink_bbox(img, hour_label_box(i)) is not None, i
def test_hour_labels_only_for_known_hours():
img = view(value=weather(rain=(10, 20))).render(NOW)
assert ink_bbox(img, hour_label_box(1)) is not None
for i in range(2, 12):
assert ink_bbox(img, hour_label_box(i)) is None, i
def test_negative_temps_stay_inside_the_frame():
for temp in (-3.4, -10.4, -19.6):
img = view(value=weather(temp=temp)).render(NOW)
box = ink_bbox(img, (380, 104, 471, 150))
assert box is not None and box[2] < 466, temp
def test_negative_temp_draws_a_minus():
cold = view(value=weather(temp=-3.4)).render(NOW)
warm = view(value=weather(temp=3.4)).render(NOW)
cold_box = ink_bbox(cold, (84, 180, 204, 236))
assert cold_box is not None and cold_box[2] < 200
assert ImageChops.difference(cold.convert("RGB"), warm.convert("RGB")).getbbox() is not None
def test_sunday_inverts_last_weekday_cell():
sunday = datetime(2026, 10, 25, 9, 0, 0)
img = view(value=weather()).render(sunday)
assert img.getpixel((402 + 1, 15)) == INK # NE cell
assert img.getpixel((12 + 1, 15)) != INK # PO cell
def test_thursday_inverts_fourth_cell():
img = view(value=weather()).render(NOW)
assert img.getpixel((12 + 3 * 65 + 1, 15)) == INK # ČT
assert img.getpixel((12 + 1, 15)) != INK
assert not same(cold, warm)
def test_fewer_than_twelve_hours_still_renders():
@@ -139,8 +185,52 @@ def test_unknown_weather_code_renders():
assert view(value=weather(code=999)).render(NOW).size == (480, 320)
def test_two_digit_negative_temps_stay_clear_of_the_divider():
for temp in (-10.4, -19.6):
img = view(value=weather(temp=temp)).render(NOW)
box = ink_bbox(img, (84, 180, 204, 236))
assert box is not None and box[2] < 200, temp
# night: from sunset to sunrise the frame is a reverse LCD
def test_is_night_between_sunset_and_sunrise():
w = weather() # sunrise 7:20, sunset 17:45
assert is_night(datetime(2026, 10, 22, 21, 0), w)
assert is_night(datetime(2026, 10, 22, 5, 30), w)
assert not is_night(datetime(2026, 10, 22, 12, 45), w)
def test_is_night_flips_exactly_at_sunrise_and_sunset():
w = weather()
assert not is_night(datetime(2026, 10, 22, 7, 20), w)
assert is_night(datetime(2026, 10, 22, 7, 19), w)
assert not is_night(datetime(2026, 10, 22, 17, 44), w)
assert is_night(datetime(2026, 10, 22, 17, 45), w)
def test_is_night_uses_todays_sun_times():
days = (day(date(2026, 10, 21), sunset=time(16, 0)), day(date(2026, 10, 22), sunset=time(17, 45)))
assert not is_night(datetime(2026, 10, 22, 16, 30), weather(days=days))
def test_is_night_without_today_uses_the_closest_known_day():
# data a week old (fetches failing): sunrise moves only minutes a day, so old times are close enough
days = (day(date(2026, 10, 15), sunrise=time(7, 8), sunset=time(17, 58)),)
assert is_night(datetime(2026, 10, 22, 21, 0), weather(days=days))
assert not is_night(datetime(2026, 10, 22, 12, 0), weather(days=days))
def test_is_night_without_any_forecast_stays_day():
assert not is_night(datetime(2026, 10, 22, 23, 0), None)
assert not is_night(datetime(2026, 10, 22, 23, 0), weather(days=()))
def test_night_frame_is_dark():
night = view(value=weather()).render(datetime(2026, 10, 22, 21, 0, 0))
day_ = view(value=weather()).render(NOW)
assert sum(night.getpixel((2, 2))) < 100
assert day_.getpixel((2, 2)) == BG
def test_night_patch_matches_full_render_region():
v = view(value=weather())
at = datetime(2026, 10, 22, 21, 0, 8)
patch = v.patch(at)
full = v.render(at)
region = full.crop((patch.x, patch.y, patch.x + patch.image.width, patch.y + patch.image.height))
assert same(region, patch.image)
assert sum(patch.image.getpixel((0, 0))) < 100