Skip to content

Commit 0bcb8ff

Browse files
committed
fix: better handle empty sensor responses and improve logging
1 parent 3c3d439 commit 0bcb8ff

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/blueair_api/http_aws_blueair.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@ async def request_with_errors_wrapper(*args, **kwargs) -> ClientResponse:
3939
status_code = response.status
4040
try:
4141
response_json = await response.json(content_type=None)
42-
if "statusCode" in response_json:
43-
_LOGGER.debug("response json found, checking status code from response")
44-
status_code = response_json["statusCode"]
42+
if response_json is not None:
43+
if "statusCode" in response_json:
44+
_LOGGER.debug("response json found, checking status code from response")
45+
status_code = response_json["statusCode"]
4546
except Exception as e:
4647
_LOGGER.error(f"Error parsing response for errors {e}")
4748
raise e
4849
if status_code == 200:
4950
_LOGGER.debug("response 200")
5051
return response
5152
if 400 <= status_code <= 500:
52-
_LOGGER.debug("auth error")
53+
_LOGGER.debug(f"auth error, {status_code}")
5354
url = kwargs["url"]
5455
response_text = await response.text()
5556
if "accounts.login" in url:

src/blueair_api/intermediate_representation_aws.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ class SensorRecord:
123123

124124
class SensorHistory(list[SensorRecord]):
125125
def __init__(self, response):
126-
sensors = response[0]["sensors"]
127-
datapoints = response[0]["datapoints"]
126+
if response is None:
127+
sensors = []
128+
datapoints = []
129+
else:
130+
sensors = response[0]["sensors"]
131+
datapoints = response[0]["datapoints"]
128132
sensor_records = []
129133
for datapoint in datapoints:
130134
values = {}

0 commit comments

Comments
 (0)