From 7a10f56c35e798c968cc54ec3e6ca46da99fed34 Mon Sep 17 00:00:00 2001 From: Erik Kastelec Date: Mon, 8 May 2023 07:32:16 +0200 Subject: [PATCH] Handle request failure for some of the modules #66 --- custom_components/wemportal/manifest.json | 2 +- custom_components/wemportal/wemportalapi.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/custom_components/wemportal/manifest.json b/custom_components/wemportal/manifest.json index 83d9fd9..0b99f43 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.5", + "version": "1.5.6", "codeowners": [ "@erikkastelec" ], diff --git a/custom_components/wemportal/wemportalapi.py b/custom_components/wemportal/wemportalapi.py index dc42228..550abed 100644 --- a/custom_components/wemportal/wemportalapi.py +++ b/custom_components/wemportal/wemportalapi.py @@ -291,6 +291,7 @@ def get_devices(self): break def get_parameters(self): + assert self.modules is not None for device_id in self.data.keys(): if self.data[device_id]["ConnectionStatus"] != 0: continue @@ -304,9 +305,17 @@ def get_parameters(self): "ModuleIndex": values["Index"], "ModuleType": values["Type"], } - response = self.make_api_call( - "https://www.wemportal.com/app/EventType/Read", data=data - ) + try: + response = self.make_api_call( + "https://www.wemportal.com/app/EventType/Read", data=data + ) + except WemPortalError as exc: + if isinstance(exc, reqs.exceptions.HTTPError) and exc.response.status_code == 400: + _LOGGER.error("Could not fetch parameters for device %s for index %s and type %s", device_id, values["Index"], values["Type"]) + delete_candidates.append((values["Index"], values["Type"])) + continue + else: + raise _LOGGER.debug(response.json()) parameters = {} try: