mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Map ipma weather condition codes once (#98512)
This commit is contained in:
parent
2c48f0e416
commit
a2e619155a
@ -1,4 +1,6 @@
|
|||||||
"""Constants for IPMA component."""
|
"""Constants for IPMA component."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.components.weather import (
|
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)
|
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_CLOUDY: [4, 5, 24, 25, 27],
|
||||||
ATTR_CONDITION_FOG: [16, 17, 26],
|
ATTR_CONDITION_FOG: [16, 17, 26],
|
||||||
ATTR_CONDITION_HAIL: [21, 22],
|
ATTR_CONDITION_HAIL: [21, 22],
|
||||||
@ -48,5 +50,10 @@ CONDITION_CLASSES = {
|
|||||||
ATTR_CONDITION_EXCEPTIONAL: [],
|
ATTR_CONDITION_EXCEPTIONAL: [],
|
||||||
ATTR_CONDITION_CLEAR_NIGHT: [-1],
|
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"
|
ATTRIBUTION = "Instituto Português do Mar e Atmosfera"
|
||||||
|
@ -37,7 +37,7 @@ from homeassistant.util import Throttle
|
|||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTRIBUTION,
|
ATTRIBUTION,
|
||||||
CONDITION_CLASSES,
|
CONDITION_MAP,
|
||||||
DATA_API,
|
DATA_API,
|
||||||
DATA_LOCATION,
|
DATA_LOCATION,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -135,10 +135,7 @@ class IPMAWeather(WeatherEntity, IPMADevice):
|
|||||||
if identifier == 1 and not is_up(self.hass, forecast_dt):
|
if identifier == 1 and not is_up(self.hass, forecast_dt):
|
||||||
identifier = -identifier
|
identifier = -identifier
|
||||||
|
|
||||||
return next(
|
return CONDITION_MAP.get(identifier)
|
||||||
(k for k, v in CONDITION_CLASSES.items() if identifier in v),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def condition(self):
|
def condition(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user