Improve cmd tool, write README
This commit is contained in:
parent
22276832cd
commit
993a4c1d79
44
README.md
44
README.md
@ -1 +1,43 @@
|
|||||||
# pyhOn
|
**This python package is unofficial and is not related in any way to Haier. It was developed by reversed engineered requests and can stop working at anytime!**
|
||||||
|
|
||||||
|
# pyhOn
|
||||||
|
Control your Haier appliances with python!
|
||||||
|
### Quick overview
|
||||||
|
To see the available options of the appliances from your Haier Account, use the commandline-tool `pyhOn`
|
||||||
|
```commandline
|
||||||
|
$ pyhOn --user example@mail.com --password pass123
|
||||||
|
========== Waschmaschine ==========
|
||||||
|
commands:
|
||||||
|
pauseProgram: pauseProgram command
|
||||||
|
resumeProgram: resumeProgram command
|
||||||
|
startProgram: startProgram command
|
||||||
|
stopProgram: stopProgram command
|
||||||
|
data:
|
||||||
|
actualWeight: 0
|
||||||
|
airWashTempLevel: 0
|
||||||
|
airWashTime: 0
|
||||||
|
antiAllergyStatus: 0
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
## Python-API
|
||||||
|
### List devices
|
||||||
|
```python
|
||||||
|
import asyncio
|
||||||
|
from pyhon import HonConnection
|
||||||
|
|
||||||
|
async def devices_example():
|
||||||
|
async with HonConnection(USER, PASSWORD) as hon:
|
||||||
|
for device in hon.devices:
|
||||||
|
print(device.nick_name)
|
||||||
|
|
||||||
|
asyncio.run(devices_example())
|
||||||
|
```
|
||||||
|
|
||||||
|
### Execute a command
|
||||||
|
```python
|
||||||
|
async with HonConnection(USER, PASSWORD) as hon:
|
||||||
|
washing_machine = hon[0]
|
||||||
|
pause_command = washing_machine.commands["pauseProgram"]
|
||||||
|
await pause_command.send()
|
||||||
|
```
|
||||||
|
@ -18,30 +18,46 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def get_arguments():
|
def get_arguments():
|
||||||
"""Get parsed arguments."""
|
"""Get parsed arguments."""
|
||||||
parser = argparse.ArgumentParser(description="hOn: Command Line Utility")
|
parser = argparse.ArgumentParser(description="pyhOn: Command Line Utility")
|
||||||
parser.add_argument("-u", "--user", help="user of haier hOn account")
|
parser.add_argument("-u", "--user", help="user for haier hOn account")
|
||||||
parser.add_argument("-p", "--password", help="password of haier hOn account")
|
parser.add_argument("-p", "--password", help="password for haier hOn account")
|
||||||
return vars(parser.parse_args())
|
return vars(parser.parse_args())
|
||||||
|
|
||||||
|
|
||||||
|
# yaml.dump() would be done the same, but needs an additional import...
|
||||||
|
def pretty_print(data, key="", intend=0, is_list=False):
|
||||||
|
if type(data) is list:
|
||||||
|
if key:
|
||||||
|
print(f"{' ' * intend}{'- ' if is_list else ''}{key}:")
|
||||||
|
intend += 1
|
||||||
|
for i, value in enumerate(data):
|
||||||
|
pretty_print(value, intend=intend, is_list=True)
|
||||||
|
elif type(data) is dict:
|
||||||
|
if key:
|
||||||
|
print(f"{' ' * intend}{'- ' if is_list else ''}{key}:")
|
||||||
|
intend += 1
|
||||||
|
for i, (key, value) in enumerate(sorted(data.items())):
|
||||||
|
if is_list and not i:
|
||||||
|
pretty_print(value, key=key, intend=intend, is_list=True)
|
||||||
|
elif is_list:
|
||||||
|
pretty_print(value, key=key, intend=intend + 1)
|
||||||
|
else:
|
||||||
|
pretty_print(value, key=key, intend=intend)
|
||||||
|
else:
|
||||||
|
print(f"{' ' * intend}{'- ' if is_list else ''}{key}{': ' if key else ''}{data}")
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
args = get_arguments()
|
args = get_arguments()
|
||||||
if not (user := args["user"]):
|
if not (user := args["user"]):
|
||||||
user = input("User of hOn account: ")
|
user = input("User for hOn account: ")
|
||||||
if not (password := args["password"]):
|
if not (password := args["password"]):
|
||||||
password = getpass("Password of hOn account: ")
|
password = getpass("Password for hOn account: ")
|
||||||
async with HonConnection(user, password) as hon:
|
async with HonConnection(user, password) as hon:
|
||||||
await hon.setup()
|
|
||||||
for device in hon.devices:
|
for device in hon.devices:
|
||||||
print(10 * "=", device.nick_name, 10 * "=")
|
print("=" * 10, device.nick_name, "=" * 10)
|
||||||
print(10 * "-", "attributes", 10 * "-")
|
pretty_print({"commands": device.commands})
|
||||||
pprint(device.attributes)
|
pretty_print({"data": device.data})
|
||||||
print(10 * "-", "statistics", 10 * "-")
|
|
||||||
pprint(device.statistics)
|
|
||||||
print(10 * "-", "commands", 10 * "-")
|
|
||||||
pprint(device.parameters)
|
|
||||||
print(10 * "-", "settings", 10 * "-")
|
|
||||||
pprint(device.settings)
|
|
||||||
|
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
|
@ -26,6 +26,7 @@ class HonConnection:
|
|||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
self._session = aiohttp.ClientSession()
|
self._session = aiohttp.ClientSession()
|
||||||
|
await self.setup()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
@ -9,7 +9,7 @@ class HonDevice:
|
|||||||
|
|
||||||
self._commands = {}
|
self._commands = {}
|
||||||
self._statistics = {}
|
self._statistics = {}
|
||||||
self._attributs = {}
|
self._attributes = {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def appliance_id(self):
|
def appliance_id(self):
|
||||||
@ -117,7 +117,7 @@ class HonDevice:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def attributes(self):
|
def attributes(self):
|
||||||
return self._attributs
|
return self._attributes
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def statistics(self):
|
def statistics(self):
|
||||||
@ -159,7 +159,7 @@ class HonDevice:
|
|||||||
async def load_attributes(self):
|
async def load_attributes(self):
|
||||||
data = await self._connector.load_attributes(self)
|
data = await self._connector.load_attributes(self)
|
||||||
for name, values in data.get("shadow").get("parameters").items():
|
for name, values in data.get("shadow").get("parameters").items():
|
||||||
self._attributs[name] = values["parNewVal"]
|
self._attributes[name] = values["parNewVal"]
|
||||||
|
|
||||||
async def load_statistics(self):
|
async def load_statistics(self):
|
||||||
self._statistics = await self._connector.load_statistics(self)
|
self._statistics = await self._connector.load_statistics(self)
|
||||||
|
4
setup.py
4
setup.py
@ -7,12 +7,12 @@ with open("README.md", "r") as f:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="pyhOn",
|
name="pyhOn",
|
||||||
version="0.0.14",
|
version="0.2.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,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
url="https://github.com/Andre0512/pyhon",
|
url="https://github.com/Andre0512/pyh0n",
|
||||||
license="MIT",
|
license="MIT",
|
||||||
platforms="any",
|
platforms="any",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
|
Loading…
Reference in New Issue
Block a user