mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add filter for duplicate NINA warnings (#84069)
Add filter for duplicate warnings
This commit is contained in:
parent
6a1c59be2c
commit
d2ee08c6fe
@ -2,6 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from async_timeout import timeout
|
||||
from pynina import ApiError, Nina
|
||||
@ -89,12 +90,38 @@ class NINADataUpdateCoordinator(
|
||||
raise UpdateFailed(err) from err
|
||||
return self._parse_data()
|
||||
|
||||
@staticmethod
|
||||
def _remove_duplicate_warnings(
|
||||
warnings: dict[str, list[Any]]
|
||||
) -> dict[str, list[Any]]:
|
||||
"""Remove warnings with the same title and expires timestamp in a region."""
|
||||
all_filtered_warnings: dict[str, list[Any]] = {}
|
||||
|
||||
for region_id, raw_warnings in warnings.items():
|
||||
|
||||
filtered_warnings: list[Any] = []
|
||||
processed_details: list[tuple[str, str]] = []
|
||||
|
||||
for raw_warn in raw_warnings:
|
||||
if (raw_warn.headline, raw_warn.expires) in processed_details:
|
||||
continue
|
||||
|
||||
processed_details.append((raw_warn.headline, raw_warn.expires))
|
||||
|
||||
filtered_warnings.append(raw_warn)
|
||||
|
||||
all_filtered_warnings[region_id] = filtered_warnings
|
||||
|
||||
return all_filtered_warnings
|
||||
|
||||
def _parse_data(self) -> dict[str, list[NinaWarningData]]:
|
||||
"""Parse warning data."""
|
||||
|
||||
return_data: dict[str, list[NinaWarningData]] = {}
|
||||
|
||||
for region_id, raw_warnings in self._nina.warnings.items():
|
||||
for region_id, raw_warnings in self._remove_duplicate_warnings(
|
||||
self._nina.warnings
|
||||
).items():
|
||||
warnings_for_regions: list[NinaWarningData] = []
|
||||
|
||||
for raw_warn in raw_warnings:
|
||||
|
@ -158,6 +158,88 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"mow.DE-NW-BN-SE030-20201014-30-011": {
|
||||
"identifier": "mow.DE-NW-BN-SE030-20201014-30-011",
|
||||
"sender": "opendata@dwd.de",
|
||||
"sent": "2021-10-11T05:21:00+01:00",
|
||||
"status": "Actual",
|
||||
"msgType": "Alert",
|
||||
"source": "PVW",
|
||||
"scope": "Public",
|
||||
"code": [
|
||||
"DVN:2",
|
||||
"id:2.49.0.0.276.0.DWD.PVW.1645004040000.5a168da8-ac20-4b6d-86be-d616526a7914"
|
||||
],
|
||||
"info": [
|
||||
{
|
||||
"language": "de-DE",
|
||||
"category": ["Met"],
|
||||
"event": "STURMBÖEN",
|
||||
"responseType": ["Prepare"],
|
||||
"urgency": "Immediate",
|
||||
"severity": "Moderate",
|
||||
"certainty": "Likely",
|
||||
"eventCode": [
|
||||
{
|
||||
"valueName": "PROFILE_VERSION",
|
||||
"value": "2.1.11"
|
||||
},
|
||||
{
|
||||
"valueName": "LICENSE",
|
||||
"value": "© GeoBasis-DE / BKG 2019 (Daten modifiziert)"
|
||||
},
|
||||
{
|
||||
"valueName": "II",
|
||||
"value": "52"
|
||||
},
|
||||
{
|
||||
"valueName": "GROUP",
|
||||
"value": "WIND"
|
||||
},
|
||||
{
|
||||
"valueName": "AREA_COLOR",
|
||||
"value": "251 140 0"
|
||||
}
|
||||
],
|
||||
"effective": "2021-11-01T03:20:00+01:00",
|
||||
"onset": "2021-11-01T05:20:00+01:00",
|
||||
"expires": "3021-11-22T05:19:00+01:00",
|
||||
"senderName": "Deutscher Wetterdienst",
|
||||
"headline": "Ausfall Notruf 112",
|
||||
"description": "Es treten Sturmböen mit Geschwindigkeiten zwischen 70 km/h (20m/s, 38kn, Bft 8) und 85 km/h (24m/s, 47kn, Bft 9) aus westlicher Richtung auf. In Schauernähe sowie in exponierten Lagen muss mit schweren Sturmböen bis 90 km/h (25m/s, 48kn, Bft 10) gerechnet werden.",
|
||||
"instruction": "ACHTUNG! Hinweis auf mögliche Gefahren: Es können zum Beispiel einzelne Äste herabstürzen. Achten Sie besonders auf herabfallende Gegenstände.",
|
||||
"web": "https://www.wettergefahren.de",
|
||||
"contact": "Deutscher Wetterdienst",
|
||||
"parameter": [
|
||||
{
|
||||
"valueName": "gusts",
|
||||
"value": "70-85 [km/h]"
|
||||
},
|
||||
{
|
||||
"valueName": "exposed gusts",
|
||||
"value": "<90 [km/h]"
|
||||
},
|
||||
{
|
||||
"valueName": "wind direction",
|
||||
"value": "west"
|
||||
},
|
||||
{
|
||||
"valueName": "PHGEM",
|
||||
"value": "3243+168,3413+1,3424+52,3478+1,3495+2,3499,3639+2527,6168+1,6175+22,6199+36,6238,6241+7,6256,9956+184,10142,10154,10164+7,10173,10176+6,10186+1,10195+2,10199,10201+6,10214+4,10220,10249+117,10368,10373+2,10425+9,10436+1,10440+8,10450+1,10453+7,10462+1,10467+5,10474+2,10484+5,10773+68,10843+2,10847+9,10858,10867+8,10878+1,10882+68,10952+7,10961+2,11046,11056+1"
|
||||
},
|
||||
{
|
||||
"valueName": "ZGEM",
|
||||
"value": "3243+168,3413+1,3424+52,3478+1,3495+2,3499,3639+2527,6168+1,6175+22,6199+36,6238,6241+7,6256,9956+184,10142,10154,10164+7,10173,10176+6,10186+1,10195+2,10199,10201+6,10214+4,10220,10249+117,10368,10373+2,10425+9,10436+1,10440+8,10450+1,10453+7,10462+1,10467+5,10474+2,10484+5,10773+68,10843+2,10847+9,10858,10867+8,10878+1,10882+68,10952+7,10961+2,11046,11056+1"
|
||||
}
|
||||
],
|
||||
"area": [
|
||||
{
|
||||
"areaDesc": "Gemeinde Oberreichenbach, Gemeinde Neuweiler, Stadt Nagold, Stadt Neubulach, Gemeinde Schömberg, Gemeinde Simmersfeld, Gemeinde Simmozheim, Gemeinde Rohrdorf, Gemeinde Ostelsheim, Gemeinde Ebhausen, Gemeinde Egenhausen, Gemeinde Dobel, Stadt Bad Liebenzell, Stadt Solingen, Stadt Haiterbach, Stadt Bad Herrenalb, Gemeinde Höfen an der Enz, Gemeinde Gechingen, Gemeinde Enzklösterle, Gemeinde Gutach (Schwarzwaldbahn) und 3392 weitere."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"biw.BIWAPP-69634": {
|
||||
"identifier": "biw.BIWAPP-69634",
|
||||
"sender": "CAP@biwapp.de",
|
||||
|
@ -41,6 +41,27 @@
|
||||
"sent": "2021-10-11T05:20:00+01:00",
|
||||
"expires": "3021-11-22T05:19:00+01:00"
|
||||
},
|
||||
{
|
||||
"id": "mow.DE-NW-BN-SE030-20201014-30-011",
|
||||
"payload": {
|
||||
"version": 1,
|
||||
"type": "ALERT",
|
||||
"id": "mow.DE-NW-BN-SE030-20201014-30-011",
|
||||
"hash": "551db820a43be7e4f39283e1dfb71b212cd520c3ee478d44f43519e9c42fde1c",
|
||||
"data": {
|
||||
"headline": "Ausfall Notruf 112",
|
||||
"provider": "MOWAS",
|
||||
"severity": "Minor",
|
||||
"msgType": "Update",
|
||||
"transKeys": { "event": "BBK-EVC-040" },
|
||||
"area": { "type": "ZGEM", "data": "1+11057,100001" }
|
||||
}
|
||||
},
|
||||
"i18nTitle": { "de": "Ausfall Notruf 112" },
|
||||
"onset": "2021-11-01T05:20:00+01:00",
|
||||
"sent": "2021-10-11T05:21:00+01:00",
|
||||
"expires": "3021-11-22T05:19:00+01:00"
|
||||
},
|
||||
{
|
||||
"id": "biw.BIWAPP-69634",
|
||||
"payload": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user