Map demo and kitchen_sink weather condition codes once (#98510)
Map demo and kitchen_sink condition codes once
This commit is contained in:
parent
614d6e929d
commit
1897be1467
2 changed files with 12 additions and 6 deletions
|
@ -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."""
|
||||
|
|
|
@ -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]:
|
||||
|
|
Loading…
Add table
Reference in a new issue