Skip to content

Commit

Permalink
Fix some minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed Jun 29, 2023
1 parent 4e88bc7 commit 44f40c5
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pyhon/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ async def load_commands(self) -> None:

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:
Expand Down
2 changes: 1 addition & 1 deletion pyhon/appliances/ov.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]:

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
):
Expand Down
2 changes: 1 addition & 1 deletion pyhon/command_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def additional_data(self) -> Dict[str, Any]:
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()
Expand Down
8 changes: 5 additions & 3 deletions pyhon/connection/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ def __init__(self, path: Path):

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 = []
Expand Down
2 changes: 1 addition & 1 deletion pyhon/connection/handler/hon.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def _check_headers(self, headers: Dict[str, str]) -> Dict[str, str]:
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 (
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="pyhOn",
version="0.14.5",
version="0.14.6",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,
Expand Down

0 comments on commit 44f40c5

Please sign in to comment.