Map meteoclimatic weather condition codes once (#98514)
parent
f85c2e5a92
commit
614d6e929d
|
@ -54,3 +54,8 @@ CONDITION_CLASSES = {
|
|||
ATTR_CONDITION_WINDY: [],
|
||||
ATTR_CONDITION_WINDY_VARIANT: [],
|
||||
}
|
||||
CONDITION_MAP = {
|
||||
cond_code: cond_ha
|
||||
for cond_ha, cond_codes in CONDITION_CLASSES.items()
|
||||
for cond_code in cond_codes
|
||||
}
|
||||
|
|
|
@ -12,14 +12,13 @@ from homeassistant.helpers.update_coordinator import (
|
|||
DataUpdateCoordinator,
|
||||
)
|
||||
|
||||
from .const import ATTRIBUTION, CONDITION_CLASSES, DOMAIN, MANUFACTURER, MODEL
|
||||
from .const import ATTRIBUTION, CONDITION_MAP, DOMAIN, MANUFACTURER, MODEL
|
||||
|
||||
|
||||
def format_condition(condition):
|
||||
"""Return condition from dict CONDITION_CLASSES."""
|
||||
for key, value in CONDITION_CLASSES.items():
|
||||
if condition in value:
|
||||
return key
|
||||
"""Return condition from dict CONDITION_MAP."""
|
||||
if condition in CONDITION_MAP:
|
||||
return CONDITION_MAP[condition]
|
||||
if isinstance(condition, Condition):
|
||||
return condition.value
|
||||
return condition
|
||||
|
|
Loading…
Reference in New Issue