Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
d4c6ccdce3 | |||
9594b9ebd8 | |||
b011d98e07 | |||
ad864286fc | |||
13cff8caa0 | |||
5fc6245806 | |||
1dad0e14b8 | |||
b04c601ad6 | |||
3ec0f5a006 | |||
78bc85132f | |||
191928287f | |||
c0aab8b99d | |||
b37715d0ca | |||
411effd814 | |||
04f19c4609 | |||
a68dcac379 | |||
40cc0013a5 | |||
f2aa3dc8fd | |||
e887371bec | |||
18b0ecdd68 |
0
pyhon/__main__.py
Executable file → Normal file
0
pyhon/__main__.py
Executable file → Normal 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):
|
||||
|
14
pyhon/appliances/ov.py
Normal file
14
pyhon/appliances/ov.py
Normal file
@ -0,0 +1,14 @@
|
||||
class Appliance:
|
||||
def data(self, data):
|
||||
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
|
||||
data["attributes"]["parameters"]["temp"] = "0"
|
||||
data["attributes"]["parameters"]["onOffStatus"] = "0"
|
||||
data["attributes"]["parameters"]["remoteCtrValid"] = "0"
|
||||
data["attributes"]["parameters"]["remainingTimeMM"] = "0"
|
||||
|
||||
data["active"] = data["attributes"]["parameters"]["onOffStatus"] == "1"
|
||||
|
||||
return data
|
||||
|
||||
def settings(self, settings):
|
||||
return settings
|
@ -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
|
||||
|
@ -62,11 +62,10 @@ class HonCommand:
|
||||
return self._ancillary_parameters
|
||||
|
||||
async def send(self) -> bool:
|
||||
parameters = {
|
||||
name: parameter.value for name, parameter in self._parameters.items()
|
||||
}
|
||||
params = {k: v.value for k, v in self._parameters.items()}
|
||||
ancillary_params = {k: v.value for k, v in self._ancillary_parameters.items()}
|
||||
return await self._api.send_command(
|
||||
self._appliance, self._name, parameters, self.ancillary_parameters
|
||||
self._appliance, self._name, params, ancillary_params
|
||||
)
|
||||
|
||||
@property
|
||||
@ -90,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
|
||||
@ -109,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
|
||||
|
@ -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", {})
|
||||
|
@ -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:
|
||||
|
@ -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))
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import List, TYPE_CHECKING
|
||||
from typing import List, TYPE_CHECKING, Dict
|
||||
|
||||
from pyhon.parameter.enum import HonParameterEnum
|
||||
|
||||
@ -13,7 +13,7 @@ class HonParameterProgram(HonParameterEnum):
|
||||
super().__init__(key, {})
|
||||
self._command = command
|
||||
self._value: str = command.program
|
||||
self._values: List[str] = list(command.programs)
|
||||
self._programs: Dict[str, "HonCommand"] = command.programs
|
||||
self._typology: str = "enum"
|
||||
|
||||
@property
|
||||
@ -25,9 +25,9 @@ class HonParameterProgram(HonParameterEnum):
|
||||
if value in self.values:
|
||||
self._command.program = value
|
||||
else:
|
||||
raise ValueError(f"Allowed values {self._values}")
|
||||
raise ValueError(f"Allowed values {self.values}")
|
||||
|
||||
@property
|
||||
def values(self) -> List[str]:
|
||||
values = [v for v in self._values if all(f not in v for f in self._FILTER)]
|
||||
values = [v for v in self._programs if all(f not in v for f in self._FILTER)]
|
||||
return sorted(values)
|
||||
|
@ -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))]
|
||||
|
Reference in New Issue
Block a user