diff --git a/paperpi.example.toml b/paperpi.example.toml index 3e6eb944..468436c4 100644 --- a/paperpi.example.toml +++ b/paperpi.example.toml @@ -100,7 +100,8 @@ type = "basic_clock" # storage_days = 30 # met_no: The weather for the next 12 hours from met.no: temperature, rain and wind. -# Layouts (values for "layout"): hours_12, small, steps_3h, now, portrait_hours, portrait_now +# Layouts (values for "layout"): hours_12, three_rows, three_columns, now_and_today, six_hours, +# steps_3h, now, small, portrait_hours, portrait_now [[plugin]] id = "met_no-3a91d2f4" name = "Weather Berlin" @@ -120,6 +121,9 @@ place = "Berlin" # temperature = "C" # Rain in millimetres or inches. One of: "mm", "inch" # rain = "mm" +# Wind speed, shown by the now layout (wind barbs are always in knots). One of: "m/s", "km/h", +# "mph", "knots" +# wind = "m/s" # --- Settings every plugin has (all of them are in the first block) --- # Seconds between updates (at least 5). Leave it out to use the plugin's suggestion (shown below) # refresh = 1800 @@ -130,7 +134,8 @@ place = "Berlin" # layout = "hours_12" # met_no: The weather for the next 12 hours from met.no: temperature, rain and wind. -# Layouts (values for "layout"): hours_12, small, steps_3h, now, portrait_hours, portrait_now +# Layouts (values for "layout"): hours_12, three_rows, three_columns, now_and_today, six_hours, +# steps_3h, now, small, portrait_hours, portrait_now [[plugin]] id = "met_no-b7e40c19" name = "Weather Rio" @@ -150,6 +155,9 @@ place = "Rio" # temperature = "C" # Rain in millimetres or inches. One of: "mm", "inch" # rain = "mm" +# Wind speed, shown by the now layout (wind barbs are always in knots). One of: "m/s", "km/h", +# "mph", "knots" +# wind = "m/s" # --- Settings every plugin has (all of them are in the first block) --- # Seconds between updates (at least 5). Leave it out to use the plugin's suggestion (shown below) # refresh = 1800 diff --git a/src/paperpi/fonts/Economica-Bold.ttf b/src/paperpi/fonts/Economica-Bold.ttf new file mode 100644 index 00000000..72a4e0c0 Binary files /dev/null and b/src/paperpi/fonts/Economica-Bold.ttf differ diff --git a/src/paperpi/fonts/Economica-OFL.txt b/src/paperpi/fonts/Economica-OFL.txt new file mode 100644 index 00000000..ba31270e --- /dev/null +++ b/src/paperpi/fonts/Economica-OFL.txt @@ -0,0 +1,94 @@ +Copyright (c) 2012, Vicente Lamonaca (produccion.taller@gmail.com www.tipografia-montevideo.info www.tipotype.com), +with Reserved Font Name Economica. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/paperpi/fonts/__init__.py b/src/paperpi/fonts/__init__.py index 8355a503..3c94f101 100644 --- a/src/paperpi/fonts/__init__.py +++ b/src/paperpi/fonts/__init__.py @@ -7,8 +7,8 @@ {"name": "title", "type": "text", "font": fonts.LATO_BOLD} Without a ``font``, epdlib uses its own DejaVu Sans. Licences: ``Anton-OFL.txt``, -``Dosis-OFL.txt``, ``Lato-OFL.txt``, ``LibreCaslonText-OFL.txt``, ``Montserrat-OFL.txt``, -``Oswald-OFL.txt``. +``Dosis-OFL.txt``, ``Economica-OFL.txt``, ``Lato-OFL.txt``, ``LibreCaslonText-OFL.txt``, +``Montserrat-OFL.txt``, ``Oswald-OFL.txt``. """ from pathlib import Path @@ -22,6 +22,10 @@ #: Font License 1.1, from Google Fonts: the static SemiBold file that PaperPi v1 shipped. DOSIS_SEMIBOLD = str(FOLDER / "Dosis-SemiBold.ttf") +#: Economica Bold by Vicente Lamonaca, under the SIL Open Font License 1.1, from Google +#: Fonts: the static Bold file that PaperPi v1 shipped. Narrow, so large numbers fit. +ECONOMICA_BOLD = str(FOLDER / "Economica-Bold.ttf") + #: Lato Bold and Lato Italic by Łukasz Dziedzic, under the SIL Open Font License 1.1, from #: Google Fonts (github.com/google/fonts, folder ofl/lato). LATO_BOLD = str(FOLDER / "Lato-Bold.ttf") diff --git a/src/paperpi/plugins/met_no/README.md b/src/paperpi/plugins/met_no/README.md index 6820fdc4..67cbfd1e 100644 --- a/src/paperpi/plugins/met_no/README.md +++ b/src/paperpi/plugins/met_no/README.md @@ -42,18 +42,28 @@ Feathers add up: a long and a short feather is 15 knots; a triangle and two long ## Layouts -| Layout | Shows | -| -------------------- | ----------------------------------------------------------------------------------- | -| `hours_12` (default) | the summary, an icon every 2 hours, then per hour the rain, temperature and wind | -| `steps_3h` | the summary, then 4 steps of 3 hours: icon, lowest and highest temperature, rain, wind | -| `now` | the current hour, large: icon, temperature and wind barb, with the summary below | -| `small` | for tiny screens (2" to 3"): a big icon, the temperature now, max, min and rain | -| `portrait_hours` | for upright screens: the summary, then one row per hour | -| `portrait_now` | for upright screens: a large icon for the current hour, then the summary | - -| `hours_12` | `steps_3h` | `now` | +| Layout | Shows | +| -------------------- | ------------------------------------------------------------------------------------------ | +| `hours_12` (default) | the summary, an icon every 2 hours, then per hour the rain, temperature and wind | +| `three_rows` | now, +3 and +6 hours as rows: time, icon, temperature, rain and wind | +| `three_columns` | now, +3 and +6 hours as columns: time, icon, a large temperature and rain | +| `now_and_today` | the icon and temperature now; the highest and lowest temperature, and when the rain starts | +| `six_hours` | every 2 hours: hour, icon, temperature, and a bar with the rain of both hours | +| `steps_3h` | 4 steps of 3 hours: icon, highest temperature and rain | +| `now` | the current hour only, large: icon, temperature, and the wind as an arrow with its speed | +| `small` | for tiny screens (2" to 3"): a big icon, the temperature now, max, min and rain | +| `portrait_hours` | for upright screens: the summary, then one row per hour | +| `portrait_now` | for upright screens: a large icon for the current hour, then the summary | + +All layouts from `three_rows` to `now` are made to be read from across the room: few items and large, bold text. + +| `three_rows` | `three_columns` | `now_and_today` | |---|---|---| -| ![hours_12](../../../../tests/images/met_no-hours_12-berlin-9in7.png) | ![steps_3h](../../../../tests/images/met_no-steps_3h-berlin-9in7.png) | ![now](../../../../tests/images/met_no-now-berlin-9in7.png) | +| ![three_rows](../../../../tests/images/met_no-three_rows-berlin-9in7.png) | ![three_columns](../../../../tests/images/met_no-three_columns-berlin-9in7.png) | ![now_and_today](../../../../tests/images/met_no-now_and_today-berlin-9in7.png) | + +| `six_hours` | `steps_3h` | `now` | +|---|---|---| +| ![six_hours](../../../../tests/images/met_no-six_hours-berlin-9in7.png) | ![steps_3h](../../../../tests/images/met_no-steps_3h-berlin-9in7.png) | ![now](../../../../tests/images/met_no-now-berlin-9in7.png) | | `small`, 2.13" | `portrait_hours`, upright | `portrait_now`, upright | `hours_12`, °F and inches, 7.5" | |---|---|---|---| @@ -78,8 +88,9 @@ Note: a saved forecast older than 6 hours is not used. Then the plugin's card on | `place` | `""` | name shown at the top, e.g. `"Berlin"`; without it, the coordinates are shown | | `temperature` | `"C"` | `"C"` (Celsius) or `"F"` (Fahrenheit) | | `rain` | `"mm"` | `"mm"` or `"inch"` | +| `wind` | `"m/s"` | `"m/s"`, `"km/h"`, `"mph"` or `"knots"`: the wind speed in the `now` layout | -Wind is always in knots, because the barbs are drawn in knots. +Wind barbs are always in knots, whatever `wind` is set to. The plugin asks for a new picture every 30 minutes unless you change `refresh`. met.no updates its forecasts about once an hour. @@ -99,7 +110,7 @@ layout = "steps_3h" # optional; without it: hours_12 ## Credits -The weather data is from [MET Norway](https://www.met.no/en), under the [Creative Commons 4.0 BY International](https://creativecommons.org/licenses/by/4.0/) license. The screen shows "Data: MET Norway", as the license asks. The weather icons are met.no's own, from [github.com/metno/weathericons](https://github.com/metno/weathericons), under the MIT license ([`icons/LICENSE`](icons/LICENSE)). +The weather data is from [MET Norway](https://www.met.no/en), under the [Creative Commons 4.0 BY International](https://creativecommons.org/licenses/by/4.0/) license. The screen shows "Data: MET Norway", as the license asks. The weather icons are met.no's own, from [github.com/metno/weathericons](https://github.com/metno/weathericons), under the MIT license ([`icons/LICENSE`](icons/LICENSE)). The large text uses Economica Bold by Vicente Lamonaca, under the SIL Open Font License 1.1 ([`fonts/Economica-OFL.txt`](../../fonts/Economica-OFL.txt)). ## For developers diff --git a/src/paperpi/plugins/met_no/__init__.py b/src/paperpi/plugins/met_no/__init__.py index f37e8129..2a2f6b8d 100644 --- a/src/paperpi/plugins/met_no/__init__.py +++ b/src/paperpi/plugins/met_no/__init__.py @@ -19,7 +19,7 @@ from ...plugin import Context, Plugin, PluginSettings, ready, setting from . import barbs, forecast from .forecast import Forecast, Hour -from .layouts import HOURS, LAYOUTS +from .layouts import HOURS, LAYOUTS, PICKS log = logging.getLogger(__name__) @@ -81,6 +81,11 @@ class Settings(PluginSettings): rain: Literal["mm", "inch"] = setting( "mm", group="Units", description="Rain in millimetres or inches" ) + wind: Literal["m/s", "km/h", "mph", "knots"] = setting( + "m/s", + group="Units", + description="Wind speed, shown by the now layout (wind barbs are always in knots)", + ) @dataclass(frozen=True) @@ -200,6 +205,49 @@ def rain_summary_text(s: forecast.Summary, settings: Settings, zone) -> str: return f"Rain {total} {rain_unit(settings)}, {spells_text(s.spells, zone)}" +#: Wind speed units: the number to multiply m/s by, and the text shown after the speed. +WIND_UNITS = { + "m/s": (1.0, "m/s"), + "km/h": (3.6, "km/h"), + "mph": (2.236936, "mph"), + "knots": (forecast.KNOTS, "kn"), +} + + +def wind_text(speed: float, unit: str) -> str: + """ "4 m/s": a wind speed in m/s, in the chosen unit.""" + factor, name = WIND_UNITS[unit] + return f"{round(speed * factor)} {name}" + + +def wind_arrow(wind_from: float): + """A plain, thick arrow that points where the wind is going: easier to see from a + distance than a barb. Drawn larger than shown, like the rain bars.""" + size = 400 + picture = Image.new("L", (size, size), 255) + draw = ImageDraw.Draw(picture) + middle = size / 2 + draw.line((middle, 60, middle, size - 110), fill=0, width=36) + draw.polygon( + [(middle - 90, size - 150), (middle + 90, size - 150), (middle, size - 20)], fill=0 + ) + # Drawn pointing down: wind from the north (0°) goes south. Turned clockwise from there. + return picture.rotate(-wind_from, resample=Image.Resampling.BICUBIC, fillcolor=255) + + +def rain_amount(mm: float, settings: Settings) -> str: + """ "3.4 mm", or "dry" when it doesn't rain.""" + number = rain_text(mm, settings.rain) + return f"{number} {rain_unit(settings)}" if number else "dry" + + +def rain_start_text(s: forecast.Summary, zone) -> str: + """ "Rain from 13:00", or "No rain".""" + if not s.spells: + return "No rain" + return f"Rain from {s.spells[0][0].astimezone(zone):%H}:00" + + def summary_text(s: forecast.Summary, settings: Settings, zone) -> str: return f"{temperatures_text(s, settings)} · {rain_summary_text(s, settings, zone)}" @@ -270,7 +318,36 @@ def wind(hour: Hour): "now_temp": lambda: f"{degrees(hours[0].temperature, t)}{t}", "now_icon": lambda: icon(hours[0].symbol), "now_barb": lambda: wind(hours[0]), + "now_degrees": lambda: degrees(hours[0].temperature, t), + "now_arrow": lambda: wind_arrow(hours[0].wind_from), + "now_wind": lambda: wind_text(hours[0].wind_speed, settings.wind), + "high": lambda: f"Max {degrees(summary.high, t)}", + "low": lambda: f"Min {degrees(summary.low, t)}", + "rain_start": lambda: rain_start_text(summary, zone), } + for k, i in enumerate(PICKS): + if i >= len(hours): + break + hour = hours[i] + makers |= { + f"pick_time_{k}": lambda h=hour: f"{local(h.time):%H:%M}", + f"pick_name_{k}": lambda h=hour, k=k: "Now" if k == 0 else f"{local(h.time):%H:%M}", + f"pick_icon_{k}": lambda h=hour: icon(h.symbol), + f"pick_temp_{k}": lambda h=hour: degrees(h.temperature, t), + f"pick_rain_{k}": lambda h=hour: rain_amount(h.rain, settings), + f"pick_barb_{k}": lambda h=hour: wind(h), + } + pairs = [hours[i : i + 2] for i in range(0, len(hours), 2)] + wet = [sum(h.rain for h in pair if h.rain >= forecast.WET) for pair in pairs] + pair_top = max([2 * 2.0, *wet]) # like the hourly bars: at least 2 mm per hour + for k, (pair, mm) in enumerate(zip(pairs, wet, strict=True)): + makers |= { + f"pair_hour_{k}": lambda h=pair[0]: f"{local(h.time):%H}", + f"pair_icon_{k}": lambda h=pair[0]: icon(h.symbol), + f"pair_temp_{k}": lambda h=pair[0]: degrees(h.temperature, t), + f"pair_bar_{k}": lambda mm=mm: rain_bar(mm, pair_top), + f"pair_mm_{k}": lambda mm=mm: rain_text(mm, unit), + } for i, hour in enumerate(hours): makers |= { f"bar_{i}": lambda h=hour: rain_bar(h.rain, top), @@ -285,19 +362,17 @@ def wind(hour: Hour): makers[f"icon_{i // 2}"] = lambda h=hour: icon(h.symbol) for k in range(len(hours) // 3): part = hours[3 * k : 3 * k + 3] - low, high = (degrees(f(h.temperature for h in part), t) for f in (min, max)) - mm = rain_text(sum(h.rain for h in part if h.rain >= forecast.WET), unit) + mm = sum(h.rain for h in part if h.rain >= forecast.WET) # The icon of the wettest hour, so it matches the rain shown under it; when dry, - # the middle hour's, like the wind. + # the middle hour's. wettest = max(part, key=lambda h: h.rain) shown = wettest if wettest.rain >= forecast.WET else part[1] end = part[-1].time + timedelta(hours=1) makers |= { f"step_{k}": lambda p=part, e=end: f"{local(p[0].time):%H}–{end_hour(e, zone)}", f"step_icon_{k}": lambda h=shown: icon(h.symbol), - f"step_temp_{k}": lambda lo=low, hi=high: lo if lo == hi else f"{lo[:-1]}–{hi}", - f"step_rain_{k}": lambda mm=mm: f"{mm} {rain_unit(settings)}" if mm else "", - f"step_barb_{k}": lambda p=part: wind(p[1]), # the wind at the middle hour + f"step_temp_{k}": lambda p=part: degrees(max(h.temperature for h in p), t), + f"step_rain_{k}": lambda mm=mm: rain_amount(mm, settings), } wanted = PLUGIN.layout(context.layout, settings).blocks return {name: make() for name, make in makers.items() if name in wanted} @@ -346,9 +421,13 @@ def _sample() -> Weather: layouts=LAYOUTS, layout_titles={ "hours_12": "Next 12 hours", - "small": "Small: right now", + "three_rows": "Three rows: now, +3 and +6 hours", + "three_columns": "Three columns: now, +3 and +6 hours", + "now_and_today": "Right now and today", + "six_hours": "Every 2 hours", "steps_3h": "Every 3 hours", "now": "Right now, large", + "small": "Small: right now", "portrait_hours": "Upright: hour by hour", "portrait_now": "Upright: right now", }, diff --git a/src/paperpi/plugins/met_no/layouts.py b/src/paperpi/plugins/met_no/layouts.py index 912a60ca..d923600e 100644 --- a/src/paperpi/plugins/met_no/layouts.py +++ b/src/paperpi/plugins/met_no/layouts.py @@ -2,14 +2,26 @@ Block names with a number are filled per hour (``hour_0`` ... ``hour_11``: ``bar``, ``hbar``, ``mm``, ``hour``, ``temp``, ``barb``, ``hicon``), per 2 hours (``icon_0`` ... ``icon_5``) or -per 3-hour step (``step``, ``step_icon``, ``step_temp``, ``step_rain``, ``step_barb``, 0-3). -The others: ``place``, ``updated``, ``summary`` (or ``temperatures`` and ``rain`` on two -lines), ``now_temp``, ``now_icon``, ``now_barb``. Rows have no gaps, so in ``hours_12`` the 6 -icons line up with the 12 hour columns. +per 3-hour step (``step``, ``step_icon``, ``step_temp``, ``step_rain``, 0-3), per 2-hour +pair (``pair_hour``, ``pair_icon``, ``pair_temp``, ``pair_bar``, ``pair_mm``, 0-5) or for +now, +3 and +6 hours (``pick_time``, ``pick_name``, ``pick_icon``, ``pick_temp``, +``pick_rain``, ``pick_barb``, 0-2). The others: ``place``, ``updated``, ``summary`` (or +``temperatures`` and ``rain`` on two lines), ``high``, ``low``, ``rain_start``, +``now_temp``, ``now_degrees``, ``now_icon``, ``now_barb``, ``now_arrow``, ``now_wind``. Rows +have no gaps, so in ``hours_12`` the 6 icons line up with the 12 hour columns. + +The layouts after ``hours_12`` are made to be read from across the room: few items, large +text in a narrow bold font, lines between the parts. """ +from ... import fonts + PAD = 0.008 HOURS = 12 +#: The hours shown by ``three_rows`` and ``three_columns``: now, +3 and +6 hours. +PICKS = (0, 3, 6) +#: The line between rows or columns. +LINE = {"pixels": 4} def _text(name, sample, size=1.0, align="center", **more) -> dict: @@ -28,6 +40,36 @@ def _image(name, size=1.0, fit="contain", **more) -> dict: return {"name": name, "type": "image", "size": size, "fit": fit, "padding": PAD, **more} +def _bold(name, sample, size=1.0, align="center", **more) -> dict: + return _text(name, sample, size, align, font=fonts.ECONOMICA_BOLD, padding=0.01, **more) + + +def _line(name: str, upright: bool = False) -> dict: + shape = "vline" if upright else "hline" + return { + "name": name, + "type": "shape", + "shape": shape, + "size": 0.03 if upright else 0.06, + "line_width": LINE, + "fill": "black", + } + + +def _rain_sample(settings) -> str: + return "8.88 in" if settings.rain == "inch" else "8.8 mm" + + +def _with_lines(parts: list[dict], prefix: str, upright: bool) -> list[dict]: + """The parts with a line between each two.""" + out = [] + for k, part in enumerate(parts): + if k: + out.append(_line(f"{prefix}_{k}", upright)) + out.append(part) + return out + + def _hour_column(i: int, rain_sample: str) -> dict: return { "column": [ @@ -106,54 +148,144 @@ def small(settings) -> dict: } -def _step(k: int, rain_unit: str) -> dict: - return { - "column": [ - _text(f"step_{k}", "88–88", size=1), - _image(f"step_icon_{k}", size=2.2, rgb_support=True), - _text(f"step_temp_{k}", "-88–-88°", size=1.2), - _text(f"step_rain_{k}", f"88.8 {rain_unit}", size=0.9), - _image(f"step_barb_{k}", size=2), - ], - "gap": 0, - } +def three_rows(settings) -> dict: + """Now, +3 and +6 hours as rows, with lines between them: the time, icon, + temperature, rain and wind barb.""" + rows = [ + { + "row": [ + _bold(f"pick_time_{k}", "88:88", size=1.1, align="left"), + _image(f"pick_icon_{k}", size=0.9, rgb_support=True), + _bold(f"pick_temp_{k}", "-88°", size=1.1), + _bold(f"pick_rain_{k}", _rain_sample(settings), size=1.1), + _image(f"pick_barb_{k}", size=0.7), + ], + "gap": 0, + "size": 3, + } + for k in range(len(PICKS)) + ] + return {"column": [_header(), _line("line_0"), *_with_lines(rows, "line", False)], "gap": 0} -def steps_3h(settings) -> dict: - """The next 12 hours in 4 steps of 3 hours: icon, lowest and highest temperature, rain - and the wind at the middle hour of each step.""" - unit = "in" if settings.rain == "inch" else "mm" +def three_columns(settings) -> dict: + """Now, +3 and +6 hours as columns, with lines between them: the time, icon, a large + temperature and the rain. No wind.""" + columns = [ + { + "column": [ + _bold(f"pick_name_{k}", "88:88", size=1), + _image(f"pick_icon_{k}", size=1.8, rgb_support=True), + _bold(f"pick_temp_{k}", "-88°", size=2), + _bold(f"pick_rain_{k}", _rain_sample(settings), size=0.9), + ], + "gap": 0, + } + for k in range(len(PICKS)) + ] + row = {"row": _with_lines(columns, "line", True), "gap": 0, "size": 8} + return {"column": [_header(), row], "gap": 0} + + +def now_and_today(settings) -> dict: + """The icon and temperature now on the left; on the right the highest and lowest + temperature of the next 12 hours and when the rain starts.""" + t = settings.temperature return { "column": [ _header(), - _text("summary", " · ".join(_samples(settings)), size=1, align="left"), - {"row": [_step(k, unit) for k in range(HOURS // 3)], "gap": 0, "size": 7}, + { + "row": [ + { + "column": [ + _image("now_icon", size=1.4, rgb_support=True), + _bold("now_temp", f"-88°{t}", size=1.2), + ], + "gap": 0, + }, + _line("line_1", upright=True), + { + "column": [ + _bold("high", "Max -88°", align="left"), + _bold("low", "Min -88°", align="left"), + _bold("rain_start", "Rain from 88:00", align="left"), + ], + "gap": 0, + }, + ], + "gap": 0, + "size": 8, + }, ], "gap": 0, } +def six_hours(settings) -> dict: + """The next 12 hours in 6 pairs of 2 hours: the first hour, its icon and temperature, + and a bar with the rain of both hours.""" + rain = "8.88" if settings.rain == "inch" else "8.8" + columns = [ + { + "column": [ + _bold(f"pair_hour_{k}", "88", size=1), + _image(f"pair_icon_{k}", size=1.3, rgb_support=True), + _bold(f"pair_temp_{k}", "-88°", size=1.3), + _image(f"pair_bar_{k}", size=1.6, fit="stretch"), + _bold(f"pair_mm_{k}", rain, size=0.8), + ], + "gap": 0, + } + for k in range(HOURS // 2) + ] + return {"column": [_header(), {"row": columns, "gap": 0, "size": 8}], "gap": 0} + + +def steps_3h(settings) -> dict: + """The next 12 hours in 4 steps of 3 hours, with lines between them: the icon, the + highest temperature and the rain of each step. No wind.""" + columns = [ + { + "column": [ + _bold(f"step_{k}", "88–88", size=1), + _image(f"step_icon_{k}", size=1.8, rgb_support=True), + _bold(f"step_temp_{k}", "-88°", size=1.8), + _bold(f"step_rain_{k}", _rain_sample(settings), size=0.9), + ], + "gap": 0, + } + for k in range(HOURS // 3) + ] + row = {"row": _with_lines(columns, "line", True), "gap": 0, "size": 8} + return {"column": [_header(), row], "gap": 0} + + def now(settings) -> dict: - """The next hour, large: icon, temperature and wind barb, with the summary below.""" + """The current hour only, large: the icon, temperature, and the wind as a plain arrow + with its speed.""" return { "column": [ _header(), { "row": [ - _image("now_icon", size=3, rgb_support=True), + _image("now_icon", rgb_support=True), { "column": [ - _text("now_temp", f"-88°{settings.temperature}", size=3), - _image("now_barb", size=2), + _bold("now_degrees", "-88°", size=2.2), + { + "row": [ + _image("now_arrow", size=0.6), + _bold("now_wind", "88 km/h", size=1.4, align="left"), + ], + "gap": 0, + }, ], "gap": 0, - "size": 2, }, ], "gap": 0, - "size": 6, + "size": 8, }, - _text("summary", " · ".join(_samples(settings)), size=1, align="left"), ], "gap": 0, } @@ -214,9 +346,13 @@ def portrait_now(settings) -> dict: LAYOUTS = { "hours_12": hours_12, - "small": small, + "three_rows": three_rows, + "three_columns": three_columns, + "now_and_today": now_and_today, + "six_hours": six_hours, "steps_3h": steps_3h, "now": now, + "small": small, "portrait_hours": portrait_hours, "portrait_now": portrait_now, } diff --git a/tests/images/met_no-now-5in65.png b/tests/images/met_no-now-5in65.png index 9dc86446..c44f886a 100644 Binary files a/tests/images/met_no-now-5in65.png and b/tests/images/met_no-now-5in65.png differ diff --git a/tests/images/met_no-now-7in5.png b/tests/images/met_no-now-7in5.png index 513506b1..2edb385e 100644 Binary files a/tests/images/met_no-now-7in5.png and b/tests/images/met_no-now-7in5.png differ diff --git a/tests/images/met_no-now-9in7.png b/tests/images/met_no-now-9in7.png index 68d4b35c..92103b98 100644 Binary files a/tests/images/met_no-now-9in7.png and b/tests/images/met_no-now-9in7.png differ diff --git a/tests/images/met_no-now-berlin-5in65.png b/tests/images/met_no-now-berlin-5in65.png index 06559a64..68830414 100644 Binary files a/tests/images/met_no-now-berlin-5in65.png and b/tests/images/met_no-now-berlin-5in65.png differ diff --git a/tests/images/met_no-now-berlin-7in5.png b/tests/images/met_no-now-berlin-7in5.png index beeda4db..f9343785 100644 Binary files a/tests/images/met_no-now-berlin-7in5.png and b/tests/images/met_no-now-berlin-7in5.png differ diff --git a/tests/images/met_no-now-berlin-9in7.png b/tests/images/met_no-now-berlin-9in7.png index 524018e9..d463a486 100644 Binary files a/tests/images/met_no-now-berlin-9in7.png and b/tests/images/met_no-now-berlin-9in7.png differ diff --git a/tests/images/met_no-now-berlin-f-5in65.png b/tests/images/met_no-now-berlin-f-5in65.png index 42ce3b68..cef6ea6c 100644 Binary files a/tests/images/met_no-now-berlin-f-5in65.png and b/tests/images/met_no-now-berlin-f-5in65.png differ diff --git a/tests/images/met_no-now-berlin-f-7in5.png b/tests/images/met_no-now-berlin-f-7in5.png index 15ea9bd2..2640f563 100644 Binary files a/tests/images/met_no-now-berlin-f-7in5.png and b/tests/images/met_no-now-berlin-f-7in5.png differ diff --git a/tests/images/met_no-now-berlin-f-9in7.png b/tests/images/met_no-now-berlin-f-9in7.png index c438e092..201c072b 100644 Binary files a/tests/images/met_no-now-berlin-f-9in7.png and b/tests/images/met_no-now-berlin-f-9in7.png differ diff --git a/tests/images/met_no-now_and_today-5in65.png b/tests/images/met_no-now_and_today-5in65.png new file mode 100644 index 00000000..1d646d5d Binary files /dev/null and b/tests/images/met_no-now_and_today-5in65.png differ diff --git a/tests/images/met_no-now_and_today-7in5.png b/tests/images/met_no-now_and_today-7in5.png new file mode 100644 index 00000000..15229677 Binary files /dev/null and b/tests/images/met_no-now_and_today-7in5.png differ diff --git a/tests/images/met_no-now_and_today-9in7.png b/tests/images/met_no-now_and_today-9in7.png new file mode 100644 index 00000000..d2da53d5 Binary files /dev/null and b/tests/images/met_no-now_and_today-9in7.png differ diff --git a/tests/images/met_no-now_and_today-berlin-5in65.png b/tests/images/met_no-now_and_today-berlin-5in65.png new file mode 100644 index 00000000..eff7dbf6 Binary files /dev/null and b/tests/images/met_no-now_and_today-berlin-5in65.png differ diff --git a/tests/images/met_no-now_and_today-berlin-7in5.png b/tests/images/met_no-now_and_today-berlin-7in5.png new file mode 100644 index 00000000..4a5d6fe3 Binary files /dev/null and b/tests/images/met_no-now_and_today-berlin-7in5.png differ diff --git a/tests/images/met_no-now_and_today-berlin-9in7.png b/tests/images/met_no-now_and_today-berlin-9in7.png new file mode 100644 index 00000000..6cd8f2e0 Binary files /dev/null and b/tests/images/met_no-now_and_today-berlin-9in7.png differ diff --git a/tests/images/met_no-now_and_today-berlin-f-5in65.png b/tests/images/met_no-now_and_today-berlin-f-5in65.png new file mode 100644 index 00000000..0cc92bfd Binary files /dev/null and b/tests/images/met_no-now_and_today-berlin-f-5in65.png differ diff --git a/tests/images/met_no-now_and_today-berlin-f-7in5.png b/tests/images/met_no-now_and_today-berlin-f-7in5.png new file mode 100644 index 00000000..4426993f Binary files /dev/null and b/tests/images/met_no-now_and_today-berlin-f-7in5.png differ diff --git a/tests/images/met_no-now_and_today-berlin-f-9in7.png b/tests/images/met_no-now_and_today-berlin-f-9in7.png new file mode 100644 index 00000000..37ee862f Binary files /dev/null and b/tests/images/met_no-now_and_today-berlin-f-9in7.png differ diff --git a/tests/images/met_no-six_hours-5in65.png b/tests/images/met_no-six_hours-5in65.png new file mode 100644 index 00000000..a68d707f Binary files /dev/null and b/tests/images/met_no-six_hours-5in65.png differ diff --git a/tests/images/met_no-six_hours-7in5.png b/tests/images/met_no-six_hours-7in5.png new file mode 100644 index 00000000..996a53c9 Binary files /dev/null and b/tests/images/met_no-six_hours-7in5.png differ diff --git a/tests/images/met_no-six_hours-9in7.png b/tests/images/met_no-six_hours-9in7.png new file mode 100644 index 00000000..79de64ce Binary files /dev/null and b/tests/images/met_no-six_hours-9in7.png differ diff --git a/tests/images/met_no-six_hours-berlin-5in65.png b/tests/images/met_no-six_hours-berlin-5in65.png new file mode 100644 index 00000000..c8ac4625 Binary files /dev/null and b/tests/images/met_no-six_hours-berlin-5in65.png differ diff --git a/tests/images/met_no-six_hours-berlin-7in5.png b/tests/images/met_no-six_hours-berlin-7in5.png new file mode 100644 index 00000000..f5ae0ba1 Binary files /dev/null and b/tests/images/met_no-six_hours-berlin-7in5.png differ diff --git a/tests/images/met_no-six_hours-berlin-9in7.png b/tests/images/met_no-six_hours-berlin-9in7.png new file mode 100644 index 00000000..13e0e061 Binary files /dev/null and b/tests/images/met_no-six_hours-berlin-9in7.png differ diff --git a/tests/images/met_no-six_hours-berlin-f-5in65.png b/tests/images/met_no-six_hours-berlin-f-5in65.png new file mode 100644 index 00000000..17b2c953 Binary files /dev/null and b/tests/images/met_no-six_hours-berlin-f-5in65.png differ diff --git a/tests/images/met_no-six_hours-berlin-f-7in5.png b/tests/images/met_no-six_hours-berlin-f-7in5.png new file mode 100644 index 00000000..e93cb498 Binary files /dev/null and b/tests/images/met_no-six_hours-berlin-f-7in5.png differ diff --git a/tests/images/met_no-six_hours-berlin-f-9in7.png b/tests/images/met_no-six_hours-berlin-f-9in7.png new file mode 100644 index 00000000..6be2dcca Binary files /dev/null and b/tests/images/met_no-six_hours-berlin-f-9in7.png differ diff --git a/tests/images/met_no-steps_3h-5in65.png b/tests/images/met_no-steps_3h-5in65.png index c155c4ff..2b589cb0 100644 Binary files a/tests/images/met_no-steps_3h-5in65.png and b/tests/images/met_no-steps_3h-5in65.png differ diff --git a/tests/images/met_no-steps_3h-7in5.png b/tests/images/met_no-steps_3h-7in5.png index a0c488e9..70fa87af 100644 Binary files a/tests/images/met_no-steps_3h-7in5.png and b/tests/images/met_no-steps_3h-7in5.png differ diff --git a/tests/images/met_no-steps_3h-9in7.png b/tests/images/met_no-steps_3h-9in7.png index f72d857f..7bf7d29f 100644 Binary files a/tests/images/met_no-steps_3h-9in7.png and b/tests/images/met_no-steps_3h-9in7.png differ diff --git a/tests/images/met_no-steps_3h-berlin-5in65.png b/tests/images/met_no-steps_3h-berlin-5in65.png index 51ccfdea..0d0288dd 100644 Binary files a/tests/images/met_no-steps_3h-berlin-5in65.png and b/tests/images/met_no-steps_3h-berlin-5in65.png differ diff --git a/tests/images/met_no-steps_3h-berlin-7in5.png b/tests/images/met_no-steps_3h-berlin-7in5.png index a7252e06..5cd7702f 100644 Binary files a/tests/images/met_no-steps_3h-berlin-7in5.png and b/tests/images/met_no-steps_3h-berlin-7in5.png differ diff --git a/tests/images/met_no-steps_3h-berlin-9in7.png b/tests/images/met_no-steps_3h-berlin-9in7.png index 5842a213..b9559c7a 100644 Binary files a/tests/images/met_no-steps_3h-berlin-9in7.png and b/tests/images/met_no-steps_3h-berlin-9in7.png differ diff --git a/tests/images/met_no-steps_3h-berlin-f-5in65.png b/tests/images/met_no-steps_3h-berlin-f-5in65.png index 667dd5b1..e6863029 100644 Binary files a/tests/images/met_no-steps_3h-berlin-f-5in65.png and b/tests/images/met_no-steps_3h-berlin-f-5in65.png differ diff --git a/tests/images/met_no-steps_3h-berlin-f-7in5.png b/tests/images/met_no-steps_3h-berlin-f-7in5.png index c6a34360..e896f016 100644 Binary files a/tests/images/met_no-steps_3h-berlin-f-7in5.png and b/tests/images/met_no-steps_3h-berlin-f-7in5.png differ diff --git a/tests/images/met_no-steps_3h-berlin-f-9in7.png b/tests/images/met_no-steps_3h-berlin-f-9in7.png index eeb43f57..32178c42 100644 Binary files a/tests/images/met_no-steps_3h-berlin-f-9in7.png and b/tests/images/met_no-steps_3h-berlin-f-9in7.png differ diff --git a/tests/images/met_no-three_columns-5in65.png b/tests/images/met_no-three_columns-5in65.png new file mode 100644 index 00000000..3db9e566 Binary files /dev/null and b/tests/images/met_no-three_columns-5in65.png differ diff --git a/tests/images/met_no-three_columns-7in5.png b/tests/images/met_no-three_columns-7in5.png new file mode 100644 index 00000000..17e313e6 Binary files /dev/null and b/tests/images/met_no-three_columns-7in5.png differ diff --git a/tests/images/met_no-three_columns-9in7.png b/tests/images/met_no-three_columns-9in7.png new file mode 100644 index 00000000..736d4712 Binary files /dev/null and b/tests/images/met_no-three_columns-9in7.png differ diff --git a/tests/images/met_no-three_columns-berlin-5in65.png b/tests/images/met_no-three_columns-berlin-5in65.png new file mode 100644 index 00000000..c3230e62 Binary files /dev/null and b/tests/images/met_no-three_columns-berlin-5in65.png differ diff --git a/tests/images/met_no-three_columns-berlin-7in5.png b/tests/images/met_no-three_columns-berlin-7in5.png new file mode 100644 index 00000000..867ed14e Binary files /dev/null and b/tests/images/met_no-three_columns-berlin-7in5.png differ diff --git a/tests/images/met_no-three_columns-berlin-9in7.png b/tests/images/met_no-three_columns-berlin-9in7.png new file mode 100644 index 00000000..a1bd3d96 Binary files /dev/null and b/tests/images/met_no-three_columns-berlin-9in7.png differ diff --git a/tests/images/met_no-three_columns-berlin-f-5in65.png b/tests/images/met_no-three_columns-berlin-f-5in65.png new file mode 100644 index 00000000..7d94c1d5 Binary files /dev/null and b/tests/images/met_no-three_columns-berlin-f-5in65.png differ diff --git a/tests/images/met_no-three_columns-berlin-f-7in5.png b/tests/images/met_no-three_columns-berlin-f-7in5.png new file mode 100644 index 00000000..c89e0674 Binary files /dev/null and b/tests/images/met_no-three_columns-berlin-f-7in5.png differ diff --git a/tests/images/met_no-three_columns-berlin-f-9in7.png b/tests/images/met_no-three_columns-berlin-f-9in7.png new file mode 100644 index 00000000..7426cafb Binary files /dev/null and b/tests/images/met_no-three_columns-berlin-f-9in7.png differ diff --git a/tests/images/met_no-three_rows-5in65.png b/tests/images/met_no-three_rows-5in65.png new file mode 100644 index 00000000..814d77d0 Binary files /dev/null and b/tests/images/met_no-three_rows-5in65.png differ diff --git a/tests/images/met_no-three_rows-7in5.png b/tests/images/met_no-three_rows-7in5.png new file mode 100644 index 00000000..7ae06fc5 Binary files /dev/null and b/tests/images/met_no-three_rows-7in5.png differ diff --git a/tests/images/met_no-three_rows-9in7.png b/tests/images/met_no-three_rows-9in7.png new file mode 100644 index 00000000..97401ba8 Binary files /dev/null and b/tests/images/met_no-three_rows-9in7.png differ diff --git a/tests/images/met_no-three_rows-berlin-5in65.png b/tests/images/met_no-three_rows-berlin-5in65.png new file mode 100644 index 00000000..67f58f76 Binary files /dev/null and b/tests/images/met_no-three_rows-berlin-5in65.png differ diff --git a/tests/images/met_no-three_rows-berlin-7in5.png b/tests/images/met_no-three_rows-berlin-7in5.png new file mode 100644 index 00000000..4f4d211d Binary files /dev/null and b/tests/images/met_no-three_rows-berlin-7in5.png differ diff --git a/tests/images/met_no-three_rows-berlin-9in7.png b/tests/images/met_no-three_rows-berlin-9in7.png new file mode 100644 index 00000000..8a5dd0df Binary files /dev/null and b/tests/images/met_no-three_rows-berlin-9in7.png differ diff --git a/tests/images/met_no-three_rows-berlin-f-5in65.png b/tests/images/met_no-three_rows-berlin-f-5in65.png new file mode 100644 index 00000000..e4e5e132 Binary files /dev/null and b/tests/images/met_no-three_rows-berlin-f-5in65.png differ diff --git a/tests/images/met_no-three_rows-berlin-f-7in5.png b/tests/images/met_no-three_rows-berlin-f-7in5.png new file mode 100644 index 00000000..65c87d24 Binary files /dev/null and b/tests/images/met_no-three_rows-berlin-f-7in5.png differ diff --git a/tests/images/met_no-three_rows-berlin-f-9in7.png b/tests/images/met_no-three_rows-berlin-f-9in7.png new file mode 100644 index 00000000..d26b7feb Binary files /dev/null and b/tests/images/met_no-three_rows-berlin-f-9in7.png differ diff --git a/tests/test_met_no.py b/tests/test_met_no.py index a1e0d6a5..b8b4aa5c 100644 --- a/tests/test_met_no.py +++ b/tests/test_met_no.py @@ -444,9 +444,11 @@ def test_barb_size(): @pytest.mark.parametrize("layout", list(met_no.LAYOUTS)) def test_every_block_gets_a_value(tmp_path, layout): - """draw fills exactly the blocks of the chosen layout, no more, no fewer.""" + """draw fills exactly the blocks of the chosen layout, no more, no fewer (the lines + between rows need no value).""" blocks = Layout(met_no.LAYOUTS[layout](Settings())).blocks - assert set(draw(PLUGIN.sample, context(tmp_path, layout))) == set(blocks) + filled = {name for name, block in blocks.items() if block.type != "shape"} + assert set(draw(PLUGIN.sample, context(tmp_path, layout))) == filled @pytest.mark.parametrize("layout", list(met_no.LAYOUTS)) @@ -513,22 +515,16 @@ def test_small_and_now(tmp_path): def test_steps_of_3_hours(tmp_path): values = draw(PLUGIN.sample, context(tmp_path, "steps_3h")) assert [values[f"step_{k}"] for k in range(4)] == ["09–12", "12–15", "15–18", "18–21"] - assert values["step_temp_0"] == "8–11°" - assert values["step_rain_0"] == "" + assert values["step_temp_0"] == "11°" # the highest of 8.4, 9.6 and 11.2 + assert values["step_rain_0"] == "dry" assert values["step_rain_2"] == "4.5 mm" # 3.4 + 1.1 + 0 - same = draw(weather(0, 0, 0), context(tmp_path, "steps_3h")) - assert same["step_temp_0"] == "10–12°" - # The icon of the wettest hour (15:00, heavy rain), the wind of the middle hour. + # The icon of the wettest hour (15:00, heavy rain). assert values["step_icon_2"].name == "heavyrain.png" - middle = PLUGIN.sample.forecast.hours[7] # 16:00, the middle of 15-18 - expected = barbs.barb(middle.wind_speed * forecast.KNOTS, middle.wind_from) - assert values["step_barb_2"].tobytes() == expected.tobytes() def test_drizzle_is_dry_in_steps_too(tmp_path): values = draw(steps_at(START, "Europe/Berlin", rain=0.05), context(tmp_path, "steps_3h")) - assert values["summary"].endswith("No rain") - assert values["step_rain_0"] == "" + assert values["step_rain_0"] == "dry" def test_step_rain_in_inches(tmp_path): @@ -540,12 +536,70 @@ def test_step_rain_in_inches(tmp_path): def test_now(tmp_path): values = draw(PLUGIN.sample, context(tmp_path, "now")) - first = PLUGIN.sample.forecast.hours[0] + first = PLUGIN.sample.forecast.hours[0] # 1.5 m/s from 200° + assert values["now_degrees"] == "8°" + assert values["now_wind"] == "2 m/s" + assert values["now_arrow"].tobytes() == met_no.wind_arrow(first.wind_from).tobytes() + assert values["now_icon"].name == "clearsky_day.png" + + +@pytest.mark.parametrize( + ("unit", "text"), + [("m/s", "10 m/s"), ("km/h", "36 km/h"), ("mph", "22 mph"), ("knots", "19 kn")], +) +def test_wind_units(unit, text): + assert met_no.wind_text(10.0, unit) == text + + +def test_wind_arrow_points_where_the_wind_goes(): + """Wind from the north goes south: the arrowhead (the dark tip) is at the bottom.""" + arrow = met_no.wind_arrow(0) + width, height = arrow.size + bottom = arrow.crop((0, height * 3 // 4, width, height)) + top = arrow.crop((0, 0, width, height // 4)) + assert sum(bottom.histogram()[:128]) > 2 * sum(top.histogram()[:128]) + # From the east: it goes west, so the head is on the left. + east = met_no.wind_arrow(90) + left = east.crop((0, 0, width // 4, height)) + right = east.crop((width * 3 // 4, 0, width, height)) + assert sum(left.histogram()[:128]) > 2 * sum(right.histogram()[:128]) + + +def test_three_rows_and_columns_show_now_plus_3_and_6_hours(tmp_path): + values = draw(PLUGIN.sample, context(tmp_path, "three_rows")) + assert [values[f"pick_time_{k}"] for k in range(3)] == ["09:00", "12:00", "15:00"] + assert [values[f"pick_temp_{k}"] for k in range(3)] == ["8°", "13°", "13°"] + assert [values[f"pick_rain_{k}"] for k in range(3)] == ["dry", "dry", "3.4 mm"] + assert values["pick_icon_2"].name == "heavyrain.png" + columns = draw(PLUGIN.sample, context(tmp_path, "three_columns")) + assert [columns[f"pick_name_{k}"] for k in range(3)] == ["Now", "12:00", "15:00"] + assert "pick_barb_0" not in columns # no wind + + +def test_three_rows_with_fewer_hours(tmp_path): + """Near the end of a saved forecast, the rows without an hour stay empty.""" + few = Weather(Forecast(hours(*[0.5] * 4), START), START, "Europe/Berlin") + values = draw(few, context(tmp_path, "three_rows")) + assert "pick_time_1" in values + assert "pick_time_2" not in values + + +def test_now_and_today(tmp_path): + values = draw(PLUGIN.sample, context(tmp_path, "now_and_today")) assert values["now_temp"] == "8°C" - assert ( - values["now_barb"].tobytes() - == barbs.barb(first.wind_speed * forecast.KNOTS, first.wind_from).tobytes() - ) + assert (values["high"], values["low"]) == ("Max 14°", "Min 8°") + assert values["rain_start"] == "Rain from 13:00" + assert draw(weather(0, 0), context(tmp_path, "now_and_today"))["rain_start"] == "No rain" + + +def test_six_hours_adds_the_rain_of_each_pair(tmp_path): + values = draw(PLUGIN.sample, context(tmp_path, "six_hours")) + assert [values[f"pair_hour_{k}"] for k in range(6)] == ["09", "11", "13", "15", "17", "19"] + assert [values[f"pair_temp_{k}"] for k in range(6)] == ["8°", "11°", "14°", "13°", "11°", "10°"] + assert [values[f"pair_mm_{k}"] for k in range(6)] == ["", "", "1.8", "4.5", "", "0.3"] + # The wettest pair fills the bar; a dry one has only the ground line. + assert values["pair_bar_3"].tobytes() == met_no.rain_bar(4.5, 4.5).tobytes() + assert values["pair_bar_0"].tobytes() == met_no.rain_bar(0, 4.5).tobytes() def test_portrait_rows_hold_their_own_hour(tmp_path): diff --git a/tests/test_web_forms.py b/tests/test_web_forms.py index c5001cf9..7099841c 100644 --- a/tests/test_web_forms.py +++ b/tests/test_web_forms.py @@ -38,7 +38,7 @@ def test_fields_are_in_groups_in_the_agreed_order(): found = forms.fields(plugins.load("met_no"), WEATHER) assert [f.key for f in found] == [ "name", - *["lat", "lon", "altitude", "place", "email", "temperature", "rain"], + *["lat", "lon", "altitude", "place", "email", "temperature", "rain", "wind"], *["display_time", "refresh", "layout", "level"], *["time_limit", "alert_reminder", "alert_max_time", "storage_mb", "storage_days"], ] @@ -55,7 +55,7 @@ def test_fields_show_the_value_or_else_the_default(): assert found["refresh"].value == found["refresh"].default == "1800" # the suggestion assert found["layout"].choices == tuple(plugins.load("met_no").layouts) # The layouts are shown by their titles; the default too. - assert found["layout"].labels[:2] == ("Next 12 hours", "Small: right now") + assert found["layout"].labels[:2] == ("Next 12 hours", "Three rows: now, +3 and +6 hours") assert found["layout"].default == "Next 12 hours" assert found["temperature"].labels == () assert found["temperature"].choices == ("C", "F") diff --git a/tests/test_web_plugins.py b/tests/test_web_plugins.py index 101cf9f5..de3234cd 100644 --- a/tests/test_web_plugins.py +++ b/tests/test_web_plugins.py @@ -182,9 +182,9 @@ def test_the_library_page_shows_titles_labels_and_names_added(client): assert page.count("Added: ") == 2 # Every word of the search is looked for in the title, type, description and labels. assert 'data-search="weather met_no the weather for the next 12 hours' in page - assert "wind. requires setup requires internet next 12 hours small: right now" in page + assert "wind. requires setup requires internet next 12 hours three rows: now, +3 and +6 hours" in page # A plugin with more than one layout lists their titles, the default first. - assert "Layouts: Next 12 hours, Small: right now, Every 3 hours," in page + assert "Layouts: Next 12 hours, Three rows: now, +3 and +6 hours, Three columns: now, +3 and +6 hours," in page assert page.count('class="hint layouts"') == sum( len(item.plugin.layouts) > 1 for item in web_plugins.library() )