Skip to content

Small improvements to the DWD Ion, along with night-time icon support

Reason for the change

Here's a small fix improving a condition by using a more specific icon, a fix improving the robustness of the datetime parser, and a new feature built on top: support for night-time icons in the DWD Ion. I prefer using DWD's data to display weather information but have been annoyed for a while that it's possible to see an icon indicating a radiant sun when it's clearly dark outside.

I did some spelunking in DWD's API and found that they do provide sunrise and sunset times in their forecast API which we already use, so I decided to hook that up to the current observation time to easily and accurately check whether to display night-time or day-time icons. If for some reason we can't obtain or parse sunrise and sunset times, we simply fall back to the earlier behaviour of showing day-time icons by default.

Note that the first commit really only changes one line but contains changes made by clang-format as well.

Original commit message(s)

  • weather/dwd: Add support for night-time icons

The DWD Ion currently shows only day-time icons which feels a bit off when checking the weather after dusk or at night. Implement the missing night-time icons and use sunrise and sunset times from DWD's forecast endpoint to accurately determine when to switch. This will only affect the display of the current conditions, the forecast icons will continue to be displayed as day-time only.

Since we need to have both observation data (for the current observation time) and forecast data (for sunrise and sunset times), only determine the icon at a very late stage in updateWeather(). Additionally, make sure to safely fall back to day-time only icons if we could not fetch sunrise or sunset times.

  • weather/dwd: Use more robust parsing for timestamps

When parsing the observationDateTime from the DWD API, we directly convert a QMap lookup by using toLongLong(). For invalid values, or when the map lookup returns QVariant() for a missing key, this will return 0, creating a valid date at millisecond offset 0. Later in the code there is a check for observationDateTime.isNull() which will therefore never return true.

For a more robust check, use a helper function parseDateFromMSecs() which will make sure the conversion to qint64 succeeded before creating the QDateTime instance. If the conversion fails for any reason, we instead return a null datetime by simply calling the empty QDateTime() constructor. These null datetimes will indicate isNull() correctly.

  • weather/dwd: fix icon for condition 2

Condition 2, "Sonne, leicht bewölkt", indicates a sunny day with few clouds. Use the more specific FewCloudsDay condition icon instead of PartlyCloudyDay, which is already correctly used for condition 3.

Merge request reports

Loading