Skip to content

Commit

Permalink
Improve no indexes handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bieniu committed Jul 7, 2021
1 parent fdbc231 commit 51ea797
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down

0 comments on commit 51ea797

Please sign in to comment.