Map ipma weather condition codes once (#98512)
parent
2c48f0e416
commit
a2e619155a
|
@ -1,4 +1,6 @@
|
|||
"""Constants for IPMA component."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components.weather import (
|
||||
|
@ -31,7 +33,7 @@ ENTITY_ID_SENSOR_FORMAT_HOME = f"{WEATHER_DOMAIN}.ipma_{HOME_LOCATION_NAME}"
|
|||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=30)
|
||||
|
||||
CONDITION_CLASSES = {
|
||||
CONDITION_CLASSES: dict[str, list[int]] = {
|
||||
ATTR_CONDITION_CLOUDY: [4, 5, 24, 25, 27],
|
||||
ATTR_CONDITION_FOG: [16, 17, 26],
|
||||
ATTR_CONDITION_HAIL: [21, 22],
|
||||
|
@ -48,5 +50,10 @@ CONDITION_CLASSES = {
|
|||
ATTR_CONDITION_EXCEPTIONAL: [],
|
||||
ATTR_CONDITION_CLEAR_NIGHT: [-1],
|
||||
}
|
||||
CONDITION_MAP = {
|
||||
cond_code: cond_ha
|
||||
for cond_ha, cond_codes in CONDITION_CLASSES.items()
|
||||
for cond_code in cond_codes
|
||||
}
|
||||
|
||||
ATTRIBUTION = "Instituto Português do Mar e Atmosfera"
|
||||
|
|
|
@ -37,7 +37,7 @@ from homeassistant.util import Throttle
|
|||
|
||||
from .const import (
|
||||
ATTRIBUTION,
|
||||
CONDITION_CLASSES,
|
||||
CONDITION_MAP,
|
||||
DATA_API,
|
||||
DATA_LOCATION,
|
||||
DOMAIN,
|
||||
|
@ -135,10 +135,7 @@ class IPMAWeather(WeatherEntity, IPMADevice):
|
|||
if identifier == 1 and not is_up(self.hass, forecast_dt):
|
||||
identifier = -identifier
|
||||
|
||||
return next(
|
||||
(k for k, v in CONDITION_CLASSES.items() if identifier in v),
|
||||
None,
|
||||
)
|
||||
return CONDITION_MAP.get(identifier)
|
||||
|
||||
@property
|
||||
def condition(self):
|
||||
|
|
Loading…
Reference in New Issue