From 11988c73a68fa273fa86eceb7c920ba2c2c9f154 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Fri, 9 Jun 2023 02:09:20 +0200 Subject: [PATCH] Fix command parameter issue hon#63 --- pyhon/appliance.py | 2 -- pyhon/commands.py | 6 +++++- pyhon/connection/api.py | 2 ++ pyhon/exceptions.py | 4 ++++ pyhon/parameter/base.py | 4 ++-- pyhon/parameter/enum.py | 4 ++++ setup.py | 2 +- 7 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pyhon/appliance.py b/pyhon/appliance.py index d7cb836..eb13e12 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -302,8 +302,6 @@ class HonAppliance: "statistics": self.statistics, "additional_data": self._additional_data, } - if self._extra and data.get("attributes"): - data = self._extra.data(data) if command_only: data.pop("attributes") data.pop("appliance") diff --git a/pyhon/commands.py b/pyhon/commands.py index a78e1b8..5c45795 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -2,6 +2,7 @@ import logging from typing import Optional, Dict, Any, List, TYPE_CHECKING, Union from pyhon import exceptions +from pyhon.exceptions import ApiError from pyhon.parameter.base import HonParameter from pyhon.parameter.enum import HonParameterEnum from pyhon.parameter.fixed import HonParameterFixed @@ -111,9 +112,12 @@ class HonCommand: params = self.parameter_groups.get("parameters", {}) ancillary_params = self.parameter_groups.get("ancillaryParameters", {}) self.appliance.sync_to_params(self.name) - return await self.api.send_command( + result = await self.api.send_command( self._appliance, self._name, params, ancillary_params ) + if not result: + raise ApiError("Can't send command") + return result @property def categories(self) -> Dict[str, "HonCommand"]: diff --git a/pyhon/connection/api.py b/pyhon/connection/api.py index ce223cc..6eebc7b 100644 --- a/pyhon/connection/api.py +++ b/pyhon/connection/api.py @@ -1,6 +1,7 @@ import json import logging from datetime import datetime +from pprint import pformat from typing import Dict, Optional from aiohttp import ClientSession @@ -188,6 +189,7 @@ class HonAPI: if json_data.get("payload", {}).get("resultCode") == "0": return True _LOGGER.error(await response.text()) + _LOGGER.error("%s - Payload:\n%s", url, pformat(data)) return False async def appliance_configuration(self) -> Dict: diff --git a/pyhon/exceptions.py b/pyhon/exceptions.py index 64e8648..e4fa290 100644 --- a/pyhon/exceptions.py +++ b/pyhon/exceptions.py @@ -12,3 +12,7 @@ class NoSessionException(Exception): class NoAuthenticationException(Exception): pass + + +class ApiError(Exception): + pass diff --git a/pyhon/parameter/base.py b/pyhon/parameter/base.py index 1ef4ee8..5111258 100644 --- a/pyhon/parameter/base.py +++ b/pyhon/parameter/base.py @@ -28,8 +28,8 @@ class HonParameter: self.check_trigger(value) @property - def intern_value(self) -> str | float: - return str(self._value) if self._value is not None else "" + def intern_value(self) -> str: + return str(self.value) @property def values(self) -> List[str]: diff --git a/pyhon/parameter/enum.py b/pyhon/parameter/enum.py index b9074c7..2dd2633 100644 --- a/pyhon/parameter/enum.py +++ b/pyhon/parameter/enum.py @@ -27,6 +27,10 @@ class HonParameterEnum(HonParameter): def values(self, values) -> None: self._values = values + @property + def intern_value(self) -> str: + return str(self._value) if self._value is not None else str(self.values[0]) + @property def value(self) -> str | float: return clean_value(self._value) if self._value is not None else self.values[0] diff --git a/setup.py b/setup.py index b350076..d9dbcd6 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.12.2", + version="0.12.3", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,