alerts

Warnings (e.g. NINA) that replace the tiles while one is active.

Data sources report active warnings from the configured source IDs as [{“id”, “title”, “text”, “severity”, “sender”, “expires”}]: “severity” is one of SEVERITY_LABELS or “”, “expires” an ISO 8601 time or None.

The source IDs to watch are stored in ALERTS_FILE (edited through the web interface); config.DEFAULT_ALERTS applies until then.

Attributes

Functions

validate(sources)

Checked copy of the source ID list; ValueError with a German message.

load(default[, path])

Load the saved warning sources.

save(sources[, path])

Validate and store the warning sources.

by_severity(alerts)

Active alerts, most severe first (stable for equal severity).

footer(alert)

One line of facts, e.g. "Warnstufe hoch · bis 26.09. 18:00 · DWD".

for_cache(active)

Shrink active alerts so that they fit into RTC memory.

not_expired(cached, now_utc)

Drop cached alerts that have expired.

Module Contents

alerts.ALERTS_FILE = 'alerts.json'
alerts.MAX_SOURCES = 20
alerts.MAX_SOURCE = 100
alerts.SEVERITY_LABELS = (('extreme', 'extrem'), ('severe', 'hoch'), ('moderate', 'mittel'), ('minor', 'gering'))
alerts.validate(sources)

Checked copy of the source ID list; ValueError with a German message.

alerts.load(default, path=ALERTS_FILE)

Load the saved warning sources.

Parameters:
  • default – Sources to use if none are saved or the file is invalid.

  • path – File to read.

Returns:

The validated list of source IDs.

alerts.save(sources, path=ALERTS_FILE)

Validate and store the warning sources.

The file is written under a temporary name and renamed, so a power cut keeps the old list.

Parameters:
  • sources – List of source IDs.

  • path – File to write.

Returns:

The stored, validated list.

Raises:

ValueError – If sources is invalid (message in German).

alerts.by_severity(alerts)

Active alerts, most severe first (stable for equal severity).

alerts.footer(alert)

One line of facts, e.g. “Warnstufe hoch · bis 26.09. 18:00 · DWD”.

alerts.CACHED_TITLE = 120
alerts.CACHED_TEXT = 400
alerts.CACHED_MORE = 5
alerts.for_cache(active)

Shrink active alerts so that they fit into RTC memory.

The most severe alert is kept with shortened texts, the others only as placeholders so that the layout can still count them (“+N weitere”).

Parameters:

active – Active alerts, most severe first.

Returns:

The shortened list.

alerts.not_expired(cached, now_utc)

Drop cached alerts that have expired.

Used while the data source cannot be reached.

Parameters:
  • cached – Alerts from the RTC state, or None.

  • now_utc – The current time as a time.gmtime() tuple.

Returns:

The alerts without expiry or with an expiry after now_utc.