From 51ea797546fe739ffc9ac3276bd10a671b739d61 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Wed, 7 Jul 2021 09:17:04 +0200 Subject: [PATCH] Improve no indexes handling --- gios/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gios/__init__.py b/gios/__init__.py index b13df38..4e81d42 100644 --- a/gios/__init__.py +++ b/gios/__init__.py @@ -93,14 +93,17 @@ async def async_update(self) -> Dict[str, Any]: # pylint:disable=too-many-branc indexes = await self._get_indexes() + for sensor, sensor_data in data.items(): + with suppress(IndexError, KeyError, TypeError): + index_level = ATTR_INDEX_LEVEL.format(sensor.lower().replace(".", "")) + sensor_data[ATTR_INDEX] = indexes[index_level]["indexLevelName"].lower() + with suppress(IndexError, KeyError, TypeError): data[ATTR_AQI.lower()] = {ATTR_NAME: ATTR_AQI} data[ATTR_AQI.lower()][ATTR_VALUE] = indexes["stIndexLevel"][ "indexLevelName" ].lower() - for sensor, sensor_data in data.items(): - index_level = ATTR_INDEX_LEVEL.format(sensor.lower().replace(".", "")) - sensor_data[ATTR_INDEX] = indexes[index_level]["indexLevelName"].lower() + return data async def _get_stations(self) -> List[Dict[str, Any]]: