From 0f630e854e709a4e412df7f35403e0379b645151 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 5 Mar 2023 18:46:51 +0100 Subject: [PATCH] Read out connection --- README.md | 7 +++++-- pyhon/__main__.py | 2 +- pyhon/appliances/wm.py | 7 +++++++ pyhon/device.py | 18 +++++++++++++++++- setup.py | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 pyhon/appliances/wm.py diff --git a/README.md b/README.md index 530016d..06a3c81 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ pip install pyhOn To get an idea of what is possible, use the commandline-tool `pyhOn`. This command requests all available options of connected appliances from the hOn api of your Haier Account. ```commandline $ pyhOn --user example@mail.com --password pass123 -========== Waschmaschine ========== +========== WM - Waschmaschine ========== commands: pauseProgram: pauseProgram command resumeProgram: resumeProgram command @@ -31,7 +31,6 @@ data: antiAllergyStatus: 0 ... ``` -The claim is, to see everything what you can see in your hOn app and to execute everything you can execute there. ## Python-API ### List devices @@ -82,3 +81,7 @@ _Unfortunately I don't have any more Haier appliances..._ ## Usage example This library is used for the custom [HomeAssistant Integration "Haier hOn"](https://github.com/Andre0512/hOn). + +## Contribution +Any kind of contribution is welcome! + diff --git a/pyhon/__main__.py b/pyhon/__main__.py index 8e6c310..65cefb8 100755 --- a/pyhon/__main__.py +++ b/pyhon/__main__.py @@ -55,7 +55,7 @@ async def main(): password = getpass("Password for hOn account: ") async with HonConnection(user, password) as hon: for device in hon.devices: - print("=" * 10, device.nick_name, "=" * 10) + print("=" * 10, device.appliance_type_name, "-", device.nick_name, "=" * 10) pretty_print({"commands": device.commands}) pretty_print({"data": device.data}) diff --git a/pyhon/appliances/wm.py b/pyhon/appliances/wm.py new file mode 100644 index 0000000..cc216df --- /dev/null +++ b/pyhon/appliances/wm.py @@ -0,0 +1,7 @@ +class Appliance: + def __init__(self, data): + self._data = data + + def get(self): + self._data["connected"] = self._data["lastConnEvent.category"] == "CONNECTED" + return self._data diff --git a/pyhon/device.py b/pyhon/device.py index f36b04c..4966c63 100644 --- a/pyhon/device.py +++ b/pyhon/device.py @@ -1,9 +1,14 @@ +import importlib +from pprint import pprint + from pyhon.commands import HonCommand class HonDevice: def __init__(self, connector, appliance): self._appliance = appliance + for values in self._appliance.pop("attributes"): + self._appliance[values["parName"]] = values["parValue"] self._connector = connector self._appliance_model = {} @@ -123,6 +128,10 @@ class HonDevice: def statistics(self): return self._statistics + @property + def appliance(self): + return self._appliance + async def load_commands(self): raw = await self._connector.load_commands(self) self._appliance_model = raw.pop("applianceModel") @@ -160,6 +169,8 @@ class HonDevice: data = await self._connector.load_attributes(self) for name, values in data.get("shadow").get("parameters").items(): self._attributes[name] = values["parNewVal"] + for name, value in data.get("lastConnEvent").items(): + self._attributes[f"lastConnEvent.{name}"] = value async def load_statistics(self): self._statistics = await self._connector.load_statistics(self) @@ -169,4 +180,9 @@ class HonDevice: @property def data(self): - return self.attributes | self.parameters | self._appliance | self._statistics + result = self.attributes | self.parameters | self.appliance | self._statistics + try: + extra = importlib.import_module(f'appliances.{self.appliance_type_name.lower()}') + return result | extra.Appliance(result).get() + except ModuleNotFoundError: + return result diff --git a/setup.py b/setup.py index 6356845..ccf7d1b 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.2.1", + version="0.2.2", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,