Map demo and kitchen_sink weather condition codes once (#98510)

Map demo and kitchen_sink condition codes once
This commit is contained in:
Erik Montnemery 2023-08-16 22:12:22 +02:00 committed by GitHub
parent 614d6e929d
commit 1897be1467
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View file

@ -46,6 +46,11 @@ CONDITION_CLASSES: dict[str, list[str]] = {
ATTR_CONDITION_WINDY_VARIANT: [],
ATTR_CONDITION_EXCEPTIONAL: [],
}
CONDITION_MAP = {
cond_code: cond_ha
for cond_ha, cond_codes in CONDITION_CLASSES.items()
for cond_code in cond_codes
}
WEATHER_UPDATE_INTERVAL = timedelta(minutes=30)
@ -237,9 +242,7 @@ class DemoWeather(WeatherEntity):
@property
def condition(self) -> str:
"""Return the weather condition."""
return [
k for k, v in CONDITION_CLASSES.items() if self._condition.lower() in v
][0]
return CONDITION_MAP[self._condition.lower()]
async def async_forecast_daily(self) -> list[Forecast]:
"""Return the daily forecast."""

View file

@ -45,6 +45,11 @@ CONDITION_CLASSES: dict[str, list[str]] = {
ATTR_CONDITION_WINDY_VARIANT: [],
ATTR_CONDITION_EXCEPTIONAL: [],
}
CONDITION_MAP = {
cond_code: cond_ha
for cond_ha, cond_codes in CONDITION_CLASSES.items()
for cond_code in cond_codes
}
async def async_setup_entry(
@ -352,9 +357,7 @@ class DemoWeather(WeatherEntity):
@property
def condition(self) -> str:
"""Return the weather condition."""
return [
k for k, v in CONDITION_CLASSES.items() if self._condition.lower() in v
][0]
return CONDITION_MAP[self._condition.lower()]
@property
def forecast(self) -> list[Forecast]: