Compare commits

...

8 Commits

Author SHA1 Message Date
d4c6ccdce3 Use parameter optional 2023-04-23 20:15:07 +02:00
9594b9ebd8 Use firmware version optional 2023-04-23 19:28:56 +02:00
b011d98e07 Expose fixed parameter as setting 2023-04-23 16:21:34 +02:00
ad864286fc Use firmware id optional 2023-04-23 14:40:39 +02:00
13cff8caa0 Bump version to 8.2 2023-04-23 03:35:13 +02:00
5fc6245806 Get values for every parameter 2023-04-22 23:08:44 +02:00
1dad0e14b8 Handle special dry level 11 2023-04-22 23:08:24 +02:00
b04c601ad6 Add log for empty token 2023-04-21 23:51:35 +02:00
9 changed files with 34 additions and 11 deletions

0
pyhon/__main__.py Executable file → Normal file
View File

View File

@ -1,4 +1,5 @@
import importlib
import logging
from contextlib import suppress
from typing import Optional, Dict, Any
from typing import TYPE_CHECKING
@ -11,6 +12,9 @@ if TYPE_CHECKING:
from pyhon import HonAPI
_LOGGER = logging.getLogger(__name__)
class HonAppliance:
def __init__(
self, api: Optional["HonAPI"], info: Dict[str, Any], zone: int = 0
@ -183,7 +187,10 @@ class HonAppliance:
async def load_attributes(self):
self._attributes = await self._api.load_attributes(self)
for name, values in self._attributes.pop("shadow").get("parameters").items():
_LOGGER.warning(self._attributes)
for name, values in (
self._attributes.pop("shadow", {}).get("parameters", {}).items()
):
self._attributes.setdefault("parameters", {})[name] = values["parNewVal"]
async def load_statistics(self):

View File

@ -1,3 +1,6 @@
from pyhon.parameter.fixed import HonParameterFixed
class Appliance:
def data(self, data):
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
@ -7,4 +10,7 @@ class Appliance:
return data
def settings(self, settings):
dry_level = settings["startProgram.dryLevel"]
if isinstance(dry_level, HonParameterFixed) and dry_level.value == "11":
settings.pop("startProgram.dryLevel", None)
return settings

View File

@ -89,8 +89,6 @@ class HonCommand:
for key, parameter in (
command._parameters | command._ancillary_parameters
).items():
if isinstance(parameter, HonParameterFixed):
continue
if key not in keys:
keys.append(key)
return keys
@ -108,7 +106,6 @@ class HonCommand:
@property
def settings(self) -> Dict[str, HonParameter]:
"""Parameters with typology enum and range"""
return {
s: param
for s in self.setting_keys

View File

@ -12,7 +12,7 @@ from pyhon.connection.auth import HonAuth
from pyhon.connection.handler.anonym import HonAnonymousConnectionHandler
from pyhon.connection.handler.hon import HonConnectionHandler
_LOGGER = logging.getLogger()
_LOGGER = logging.getLogger(__name__)
class HonAPI:
@ -74,13 +74,15 @@ class HonAPI:
"applianceType": appliance.appliance_type,
"code": appliance.info["code"],
"applianceModelId": appliance.appliance_model_id,
"firmwareId": appliance.info["eepromId"],
"macAddress": appliance.mac_address,
"fwVersion": appliance.info["fwVersion"],
"os": const.OS,
"appVersion": const.APP_VERSION,
"series": appliance.info["series"],
}
if firmware_id := appliance.info.get("eepromId"):
params["firmwareId"] = firmware_id
if firmware_version := appliance.info.get("fwVersion"):
params["fwVersion"] = firmware_version
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", {})

View File

@ -228,7 +228,10 @@ class HonAuth:
except json.JSONDecodeError:
await self._error_logger(response)
return False
self._cognito_token = json_data["cognitoUser"]["Token"]
self._cognito_token = json_data.get("cognitoUser", {}).get("Token", "")
if not self._cognito_token:
_LOGGER.error(json_data)
raise exceptions.HonAuthenticationError()
return True
async def authenticate(self) -> None:

View File

@ -1,4 +1,4 @@
from typing import Dict, Any
from typing import Dict, Any, List
from pyhon.parameter.base import HonParameter
@ -19,3 +19,7 @@ class HonParameterFixed(HonParameter):
def value(self, value: str | float) -> None:
# Fixed values seems being not so fixed as thought
self._value = value
@property
def values(self) -> List[str]:
return list(str(self.value))

View File

@ -1,4 +1,4 @@
from typing import Dict, Any
from typing import Dict, Any, List
from pyhon.parameter.base import HonParameter
@ -47,3 +47,7 @@ class HonParameterRange(HonParameter):
raise ValueError(
f"Allowed: min {self._min} max {self._max} step {self._step}"
)
@property
def values(self) -> List[str]:
return [str(i) for i in range(int(self.min), int(self.max) + 1, int(self.step))]

View File

@ -7,7 +7,7 @@ with open("README.md", "r") as f:
setup(
name="pyhOn",
version="0.8.1",
version="0.8.6",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,