diff --git a/homeassistant/components/openweathermap/const.py b/homeassistant/components/openweathermap/const.py index d53fbc136b2..1420b1170ca 100644 --- a/homeassistant/components/openweathermap/const.py +++ b/homeassistant/components/openweathermap/const.py @@ -157,3 +157,8 @@ CONDITION_CLASSES = { 904, ], } +CONDITION_MAP = { + cond_code: cond_ha + for cond_ha, cond_codes in CONDITION_CLASSES.items() + for cond_code in cond_codes +} diff --git a/homeassistant/components/openweathermap/weather_update_coordinator.py b/homeassistant/components/openweathermap/weather_update_coordinator.py index 732557363d8..cf0c941f0df 100644 --- a/homeassistant/components/openweathermap/weather_update_coordinator.py +++ b/homeassistant/components/openweathermap/weather_update_coordinator.py @@ -46,7 +46,7 @@ from .const import ( ATTR_API_WIND_BEARING, ATTR_API_WIND_GUST, ATTR_API_WIND_SPEED, - CONDITION_CLASSES, + CONDITION_MAP, DOMAIN, FORECAST_MODE_DAILY, FORECAST_MODE_HOURLY, @@ -267,7 +267,7 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator): return ATTR_CONDITION_SUNNY return ATTR_CONDITION_CLEAR_NIGHT - return [k for k, v in CONDITION_CLASSES.items() if weather_code in v][0] + return CONDITION_MAP.get(weather_code) class LegacyWeather: