From 414fbd35b949ede18d1daf9a21956f891f90aa1f Mon Sep 17 00:00:00 2001 From: Dan Raper Date: Mon, 1 Jan 2024 14:55:42 +0000 Subject: [PATCH] Fixed null CT error (#23) --- custom_components/ohme/api_client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/ohme/api_client.py b/custom_components/ohme/api_client.py index 53451b5..a1a5b32 100644 --- a/custom_components/ohme/api_client.py +++ b/custom_components/ohme/api_client.py @@ -118,6 +118,7 @@ async def _post_request(self, url, skip_json=False, data=None): data=data, headers=self._get_headers() ) as resp: + _LOGGER.debug(f"POST request to {url}, status code {resp.status}") await self._handle_api_error(url, resp) if skip_json: @@ -133,6 +134,7 @@ async def _put_request(self, url, data=None): data=json.dumps(data), headers=self._get_headers() ) as resp: + _LOGGER.debug(f"PUT request to {url}, status code {resp.status}") await self._handle_api_error(url, resp) return True @@ -144,6 +146,7 @@ async def _get_request(self, url): url, headers=self._get_headers() ) as resp: + _LOGGER.debug(f"GET request to {url}, status code {resp.status}") await self._handle_api_error(url, resp) return await resp.json() @@ -248,7 +251,7 @@ async def async_get_ct_reading(self): resp = await self._get_request(f"/v1/chargeDevices/{self._serial}/advancedSettings") # If we ever get a reading above 0, assume CT connected - if resp['clampAmps'] > 0: + if resp['clampAmps'] and resp['clampAmps'] > 0: self._ct_connected = True return resp['clampAmps']