From 44f40c531e039203343736fccbda4a53de514fa9 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Thu, 29 Jun 2023 22:08:17 +0200 Subject: [PATCH] Fix some minor issues --- pyhon/appliance.py | 4 +++- pyhon/appliances/ov.py | 2 +- pyhon/command_loader.py | 2 +- pyhon/connection/api.py | 8 +++++--- pyhon/connection/handler/hon.py | 2 +- setup.py | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pyhon/appliance.py b/pyhon/appliance.py index e8cffc3..114a72d 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -165,7 +165,9 @@ class HonAppliance: async def load_attributes(self) -> None: self._attributes = await self.api.load_attributes(self) - for name, values in self._attributes.pop("shadow").get("parameters").items(): + for name, values in ( + self._attributes.pop("shadow", {}).get("parameters", {}).items() + ): if name in self._attributes.get("parameters", {}): self._attributes["parameters"][name].update(values) else: diff --git a/pyhon/appliances/ov.py b/pyhon/appliances/ov.py index a871fb7..f406ad4 100644 --- a/pyhon/appliances/ov.py +++ b/pyhon/appliances/ov.py @@ -15,7 +15,7 @@ class Appliance(ApplianceBase): data["active"] = data["parameters"]["onOffStatus"] == "1" - if program := int(data["parameters"]["prCode"]): + if program := int(data["parameters"]["prCode"].value): if (setting := self.parent.settings["startProgram.program"]) and isinstance( setting, HonParameterProgram ): diff --git a/pyhon/command_loader.py b/pyhon/command_loader.py index 1a6a5a4..578fa57 100644 --- a/pyhon/command_loader.py +++ b/pyhon/command_loader.py @@ -55,7 +55,7 @@ class HonCommandLoader: async def load_commands(self) -> None: """Trigger loading of command data""" await self._load_data() - self._appliance_data = self._api_commands.pop("applianceModel") + self._appliance_data = self._api_commands.pop("applianceModel", {}) self._get_commands() self._add_favourites() self._recover_last_command_states() diff --git a/pyhon/connection/api.py b/pyhon/connection/api.py index c9a4588..4666c4d 100644 --- a/pyhon/connection/api.py +++ b/pyhon/connection/api.py @@ -250,9 +250,11 @@ class TestAPI(HonAPI): def _load_json(self, appliance: HonAppliance, file: str) -> Dict[str, Any]: directory = f"{appliance.appliance_type}_{appliance.appliance_model_id}".lower() - path = f"{self._path}/{directory}/{file}.json" - with open(path, "r", encoding="utf-8") as json_file: - return json.loads(json_file.read()) + if (path := self._path / directory / f"{file}.json").exists(): + with open(path, "r", encoding="utf-8") as json_file: + return json.loads(json_file.read()) + _LOGGER.warning(f"Can't open {str(path)}") + return {} async def load_appliances(self) -> List[Dict[str, Any]]: result = [] diff --git a/pyhon/connection/handler/hon.py b/pyhon/connection/handler/hon.py index f0f8574..5b7692f 100644 --- a/pyhon/connection/handler/hon.py +++ b/pyhon/connection/handler/hon.py @@ -57,7 +57,7 @@ class HonConnectionHandler(ConnectionHandler): async def _intercept( self, method: Callback, url: str | URL, *args: Any, **kwargs: Any ) -> AsyncIterator[aiohttp.ClientResponse]: - loop: int = kwargs.get("loop", 0) + loop: int = kwargs.pop("loop", 0) kwargs["headers"] = await self._check_headers(kwargs.get("headers", {})) async with method(url, *args, **kwargs) as response: if ( diff --git a/setup.py b/setup.py index c4afb9f..7d54331 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.14.5", + version="0.14.6", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,