Skip to content

Commit

Permalink
Make 'code' attribute optional, fix hon#51
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed May 16, 2023
1 parent b5af81b commit af4fbdd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pyhon/connection/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ async def load_commands(self, appliance: HonAppliance) -> Dict:
params["firmwareId"] = firmware_id
if firmware_version := appliance.info.get("fwVersion"):
params["fwVersion"] = firmware_version
if code := appliance.info.get("code"):
params["code"] = code
url: str = f"{const.API_URL}/commands/v1/retrieve"
async with self._hon.get(url, params=params) as response:
result: Dict = (await response.json()).get("payload", {})
Expand Down
21 changes: 14 additions & 7 deletions pyhon/hon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import logging
from types import TracebackType
from typing import List, Optional, Dict, Any, Type

Expand All @@ -8,6 +9,8 @@
from pyhon import HonAPI, exceptions
from pyhon.appliance import HonAppliance

_LOGGER = logging.getLogger(__name__)


class Hon:
def __init__(
Expand Down Expand Up @@ -70,13 +73,17 @@ async def _create_appliance(self, appliance_data: Dict[str, Any], zone=0) -> Non
appliance = HonAppliance(self._api, appliance_data, zone=zone)
if appliance.mac_address == "":
return
await asyncio.gather(
*[
appliance.load_attributes(),
appliance.load_commands(),
appliance.load_statistics(),
]
)
try:
await asyncio.gather(
*[
appliance.load_attributes(),
appliance.load_commands(),
appliance.load_statistics(),
]
)
except (KeyError, ValueError, IndexError) as error:
_LOGGER.exception(error)
_LOGGER.error(f"Device data - %s", appliance_data)
self._appliances.append(appliance)

async def setup(self) -> None:
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.10.6",
version="0.10.7",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,
Expand Down

0 comments on commit af4fbdd

Please sign in to comment.