+++ date = 2024-10-19T20:02:17+02:00 title = "Night-time icons for Plasma's DWD backend" [taxonomies] tags = ["kde"] [extra] related = [] +++ For a couple of weeks now I have been using Plasma's built-in weather report system. It supports various different sources for weather observations and forecasts, one of which is my preferred service, [Deutscher Wetterdienst](https://www.dwd.de) (DWD). Once the report location is set up, Plasma displays the current conditions in the tray - clicking on it gives you an overview of the next 7 days. I've been quite pleased with this; a quick glance at the icon tells you everything you need to know and the forecast is only one click away. It even supports DWD's official warning system. There is one small problem with the tray icon, however. See if you can spot it: {{ img(path="icon-day.png", format="png", alt="A screenshot of Plasma's tray showing a clipboard icon, a media control icon, and a weather icon. The weather icon is displaying a sun with few clouds in front. The tray is also showing the time. It is 23:57.", caption="Something's not quite right...") }} That's right, I couldn't have possibly taken this image given this post's timestamp is before 23:57! Good catch. More importantly, however, the icon is showing the sun when realistically it's going to be dark outside. This has been annoying me to no end, so a couple of days ago I decided to fix it. Since Plasma already comes with weather icons suited for night-time use, I really only needed a reliable way to tell when to switch to those. After some spelunking in DWD's [two](https://dwd.api.bund.dev/) [APIs](https://listed.to/@DieSieben/7851/api-des-deutschen-wetterdienstes), I found that the latter contains sunrise and sunset times for its forecast endpoint. The weather report system was already using this endpoint to fetch forecast data, so it was a rather simple lookup of two values in the API and then comparing the current observation time to those. So, after some preparatory work to make date parsing more robust, I sent a [merge request](https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4848) upstream which was promptly approved and merged. Finally I could rest easy after dusk, not having to worry about a sun chasing me around. {{ img(path="icon-night.png", format="png", alt="A screenshot of Plasma's tray showing a clipboard icon, a media control icon, and a weather icon. The weather icon is displaying a crescent moon with few clouds in front. The tray is also showing the time. It is 18:57.", caption="... much better!") }} There's some more stuff that could be improved in the DWD backend, like station availability. As far as I can tell, when using the open API, DWD limits access to weather data depending on whether or not they have the full rights to it. The API might therefore simply deny access to a station even though it is listed in in [the official index](https://www.dwd.de/DE/leistungen/klimadatendeutschland/statliste/statlex_html.html?view=nasPublication&nn=16102). There's no way to find out which station is accessible except to try them all. To get around this, the DWD backend uses a [very simple heuristic](https://invent.kde.org/plasma/plasma-workspace/-/blob/69a52cd6fbde80b087f59a633b4ff216c27ddff0/dataengines/weather/ions/dwd/ion_dwd.cpp#L396-403) based on the first digit of the station ID, since all stations starting with 0 or 1 seem to work. However, this ignores a number of other, still accessible, stations. I'm planning to look into this further, hopefully finding a better solution so that users of the DWD backend have access to as many stations as possible.