Handle json decode exception in co2signal (#100857)

* Handle json decode exception in co2signal

* Update homeassistant/components/co2signal/coordinator.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Fix import

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Jan-Philipp Benecke 2023-09-25 21:21:01 +02:00 committed by GitHub
parent ea1108503d
commit b9a3863645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from collections.abc import Mapping
from datetime import timedelta
from json import JSONDecodeError
import logging
from typing import Any, cast
@ -68,6 +69,10 @@ def get_data(hass: HomeAssistant, config: Mapping[str, Any]) -> CO2SignalRespons
wait=False,
)
except JSONDecodeError as err:
# raise occasional occurring json decoding errors as CO2Error so the data update coordinator retries it
raise CO2Error from err
except ValueError as err:
err_str = str(err)