Fix some stuff for hoover appliances
This commit is contained in:
parent
9ee5dbc956
commit
5db13a90e7
0
pyhon/__main__.py
Normal file → Executable file
0
pyhon/__main__.py
Normal file → Executable file
@ -6,6 +6,7 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
from pyhon import helper
|
from pyhon import helper
|
||||||
from pyhon.commands import HonCommand
|
from pyhon.commands import HonCommand
|
||||||
|
from pyhon.parameter.base import HonParameter
|
||||||
from pyhon.parameter.fixed import HonParameterFixed
|
from pyhon.parameter.fixed import HonParameterFixed
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -169,7 +170,8 @@ class HonAppliance:
|
|||||||
def settings(self):
|
def settings(self):
|
||||||
result = {}
|
result = {}
|
||||||
for name, command in self._commands.items():
|
for name, command in self._commands.items():
|
||||||
for key, setting in command.settings.items():
|
for key in command.setting_keys:
|
||||||
|
setting = command.settings.get(key, HonParameter(key, {}))
|
||||||
result[f"{name}.{key}"] = setting
|
result[f"{name}.{key}"] = setting
|
||||||
if self._extra:
|
if self._extra:
|
||||||
return self._extra.settings(result)
|
return self._extra.settings(result)
|
||||||
@ -187,10 +189,7 @@ class HonAppliance:
|
|||||||
|
|
||||||
async def load_attributes(self):
|
async def load_attributes(self):
|
||||||
self._attributes = await self._api.load_attributes(self)
|
self._attributes = await self._api.load_attributes(self)
|
||||||
_LOGGER.warning(self._attributes)
|
for name, values in self._attributes.pop("shadow").get("parameters").items():
|
||||||
for name, values in (
|
|
||||||
self._attributes.pop("shadow", {}).get("parameters", {}).items()
|
|
||||||
):
|
|
||||||
self._attributes.setdefault("parameters", {})[name] = values["parNewVal"]
|
self._attributes.setdefault("parameters", {})[name] = values["parNewVal"]
|
||||||
|
|
||||||
async def load_statistics(self):
|
async def load_statistics(self):
|
||||||
@ -221,4 +220,4 @@ class HonAppliance:
|
|||||||
{"commands": helper.create_command(self.commands)},
|
{"commands": helper.create_command(self.commands)},
|
||||||
whitespace="\u200B \u200B ",
|
whitespace="\u200B \u200B ",
|
||||||
)
|
)
|
||||||
return result.replace(self.mac_address, "12-34-56-78-90-ab")
|
return result.replace(self.mac_address, "xx-xx-xx-xx-xx-xx")
|
||||||
|
@ -10,12 +10,13 @@ class Appliance:
|
|||||||
data["attributes"]["parameters"]["machMode"] = "0"
|
data["attributes"]["parameters"]["machMode"] = "0"
|
||||||
data["active"] = bool(data.get("attributes", {}).get("activity"))
|
data["active"] = bool(data.get("attributes", {}).get("activity"))
|
||||||
data["pause"] = data["attributes"]["parameters"]["machMode"] == "3"
|
data["pause"] = data["attributes"]["parameters"]["machMode"] == "3"
|
||||||
program = int(data["attributes"]["parameters"]["prCode"])
|
if program := int(data["attributes"]["parameters"]["prCode"]):
|
||||||
data["programName"] = self.parent.settings["startProgram.program"].ids[program]
|
ids = self.parent.settings["startProgram.program"].ids
|
||||||
|
data["programName"] = ids.get(program, "")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def settings(self, settings):
|
def settings(self, settings):
|
||||||
dry_level = settings["startProgram.dryLevel"]
|
dry_level = settings.get("startProgram.dryLevel")
|
||||||
if isinstance(dry_level, HonParameterFixed) and dry_level.value == "11":
|
if isinstance(dry_level, HonParameterFixed) and dry_level.value == "11":
|
||||||
settings.pop("startProgram.dryLevel", None)
|
settings.pop("startProgram.dryLevel", None)
|
||||||
return settings
|
return settings
|
||||||
|
@ -24,7 +24,7 @@ class HonCommand:
|
|||||||
self._api: HonAPI = api
|
self._api: HonAPI = api
|
||||||
self._appliance: "HonAppliance" = appliance
|
self._appliance: "HonAppliance" = appliance
|
||||||
self._name: str = name
|
self._name: str = name
|
||||||
self._programs: Optional[Dict[str, "HonCommand"]] = programs or {}
|
self._programs: Optional[Dict[str, "HonCommand"]] = programs
|
||||||
self._program_name: str = program_name
|
self._program_name: str = program_name
|
||||||
self._description: str = attributes.get("description", "")
|
self._description: str = attributes.get("description", "")
|
||||||
self._parameters: Dict[str, HonParameter] = self._create_parameters(
|
self._parameters: Dict[str, HonParameter] = self._create_parameters(
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
from pyhon.parameter.base import HonParameter
|
||||||
|
|
||||||
|
|
||||||
def key_print(data, key="", start=True):
|
def key_print(data, key="", start=True):
|
||||||
result = ""
|
result = ""
|
||||||
if isinstance(data, list):
|
if isinstance(data, list):
|
||||||
@ -44,12 +47,21 @@ def pretty_print(data, key="", intend=0, is_list=False, whitespace=" "):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def get_parameter(command, parameter):
|
||||||
|
if programs := command.programs:
|
||||||
|
for program in programs.values():
|
||||||
|
if data := program.settings.get(parameter):
|
||||||
|
return data
|
||||||
|
return command.settings.get(parameter)
|
||||||
|
|
||||||
|
|
||||||
def create_command(commands, concat=False):
|
def create_command(commands, concat=False):
|
||||||
result = {}
|
result = {}
|
||||||
for name, command in commands.items():
|
for name, command in commands.items():
|
||||||
if not concat:
|
if not concat:
|
||||||
result[name] = {}
|
result[name] = {}
|
||||||
for parameter, data in command.settings.items():
|
for parameter in command.setting_keys:
|
||||||
|
data = get_parameter(command, parameter)
|
||||||
if data.typology == "enum":
|
if data.typology == "enum":
|
||||||
value = data.values
|
value = data.values
|
||||||
elif data.typology == "range":
|
elif data.typology == "range":
|
||||||
|
@ -47,7 +47,7 @@ class Hon:
|
|||||||
|
|
||||||
async def _create_appliance(self, appliance_data: Dict[str, Any], zone=0) -> None:
|
async def _create_appliance(self, appliance_data: Dict[str, Any], zone=0) -> None:
|
||||||
appliance = HonAppliance(self._api, appliance_data, zone=zone)
|
appliance = HonAppliance(self._api, appliance_data, zone=zone)
|
||||||
if appliance.mac_address is None:
|
if appliance.mac_address == "":
|
||||||
return
|
return
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*[
|
*[
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Dict, Any
|
from typing import Dict, Any, List
|
||||||
|
|
||||||
|
|
||||||
class HonParameter:
|
class HonParameter:
|
||||||
@ -17,6 +17,10 @@ class HonParameter:
|
|||||||
def value(self) -> str | float:
|
def value(self) -> str | float:
|
||||||
return self._value if self._value is not None else "0"
|
return self._value if self._value is not None else "0"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def values(self) -> List[str]:
|
||||||
|
return list(str(self.value))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def category(self) -> str:
|
def category(self) -> str:
|
||||||
return self._category
|
return self._category
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Dict, Any, List
|
from typing import Dict, Any
|
||||||
|
|
||||||
from pyhon.parameter.base import HonParameter
|
from pyhon.parameter.base import HonParameter
|
||||||
|
|
||||||
@ -19,7 +19,3 @@ class HonParameterFixed(HonParameter):
|
|||||||
def value(self, value: str | float) -> None:
|
def value(self, value: str | float) -> None:
|
||||||
# Fixed values seems being not so fixed as thought
|
# Fixed values seems being not so fixed as thought
|
||||||
self._value = value
|
self._value = value
|
||||||
|
|
||||||
@property
|
|
||||||
def values(self) -> List[str]:
|
|
||||||
return list(str(self.value))
|
|
||||||
|
2
setup.py
2
setup.py
@ -7,7 +7,7 @@ with open("README.md", "r") as f:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pyhOn",
|
name="pyhOn",
|
||||||
version="0.8.6",
|
version="0.9.0",
|
||||||
author="Andre Basche",
|
author="Andre Basche",
|
||||||
description="Control hOn devices with python",
|
description="Control hOn devices with python",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
|
Loading…
Reference in New Issue
Block a user