Read out connection

This commit is contained in:
Andre Basche 2023-03-05 18:46:51 +01:00
parent 1ef5f7a64d
commit 0f630e854e
5 changed files with 31 additions and 5 deletions

View file

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

View file

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

7
pyhon/appliances/wm.py Normal file
View file

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

View file

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

View file

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