Fix command parameter issue hon#63

This commit is contained in:
Andre Basche 2023-06-09 02:09:20 +02:00
parent 7b51caecca
commit 11988c73a6
7 changed files with 18 additions and 6 deletions

View File

@ -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")

View File

@ -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"]:

View File

@ -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:

View File

@ -12,3 +12,7 @@ class NoSessionException(Exception):
class NoAuthenticationException(Exception):
pass
class ApiError(Exception):
pass

View File

@ -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]:

View File

@ -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]

View File

@ -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,