From 369ab54a3eb574b907017d9deab0833779dfa398 Mon Sep 17 00:00:00 2001 From: Erik Kastelec Date: Sun, 7 May 2023 19:36:53 +0200 Subject: [PATCH] Improve logging #66 --- custom_components/wemportal/manifest.json | 2 +- custom_components/wemportal/wemportalapi.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/custom_components/wemportal/manifest.json b/custom_components/wemportal/manifest.json index 91d5616..0f4520a 100644 --- a/custom_components/wemportal/manifest.json +++ b/custom_components/wemportal/manifest.json @@ -4,7 +4,7 @@ "documentation": "https://github.com/erikkastelec/hass-WEM-Portal", "issue_tracker": "https://github.com/erikkastelec/hass-WEM-Portal/issues", "dependencies": [], - "version": "1.5.3", + "version": "1.5.4", "codeowners": [ "@erikkastelec" ], diff --git a/custom_components/wemportal/wemportalapi.py b/custom_components/wemportal/wemportalapi.py index 7560142..a6851fa 100644 --- a/custom_components/wemportal/wemportalapi.py +++ b/custom_components/wemportal/wemportalapi.py @@ -223,6 +223,7 @@ def get_response_details(self, response: reqs.Response): if response: try: response_data = response.json() + _LOGGER.debug(response_data) # Status we get back from server server_status = response_data["Status"] server_message = response_data["Message"] @@ -238,12 +239,15 @@ def make_api_call( if not headers: headers = self.headers if not data: + _LOGGER.debug(f"Sending GET request to {url} with headers: {headers}") response = self.session.get(url, headers=headers) else: headers["Content-Type"] = "application/json" + _LOGGER.debug(f"Sending POST request to {url} with headers: {headers} and data: {data}") response = self.session.post( url, headers=headers, data=json.dumps(data) ) + response.raise_for_status() except Exception as exc: if response and response.status_code in (401, 403) and not login_retry: @@ -263,6 +267,7 @@ def make_api_call( f"{DATA_GATHERING_ERROR} Server returned status code: {server_status} and message: {server_message}" ) from exc + _LOGGER.debug(response) return response def get_devices(self): @@ -290,6 +295,7 @@ def get_parameters(self): continue _LOGGER.debug("Fetching api parameters data for device %s", device_id) _LOGGER.debug(self.data) + _LOGGER.debug(self.modules[device_id]) delete_candidates = [] for key, values in self.modules[device_id].items(): data = {