From 3d5c8405eab058d1590d59f53dcca2836cb63dc9 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 9 Jul 2023 23:58:55 +0200 Subject: [PATCH] Improve error handling --- pyhon/appliance.py | 2 +- pyhon/connection/api.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pyhon/appliance.py b/pyhon/appliance.py index a61a362..f1ef65e 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -109,7 +109,7 @@ class HonAppliance: @property def nick_name(self) -> str: result = self._check_name_zone("nickName") - if not result or re.findall("^[xX1\\s]+$", result): + if not result or re.findall("^[xX1\\s-]+$", result): return self.model_name return result diff --git a/pyhon/connection/api.py b/pyhon/connection/api.py index a4a45f1..364bbb6 100644 --- a/pyhon/connection/api.py +++ b/pyhon/connection/api.py @@ -267,8 +267,13 @@ class TestAPI(HonAPI): _LOGGER.warning("Can't open %s", str(path)) return {} with open(path, "r", encoding="utf-8") as json_file: - data: Dict[str, Any] = json.loads(json_file.read()) - return data + text = json_file.read() + try: + data: Dict[str, Any] = json.loads(text) + return data + except json.decoder.JSONDecodeError as error: + _LOGGER.error("%s - %s", str(path), error) + return {} async def load_appliances(self) -> List[Dict[str, Any]]: result = []