mirror of
https://github.com/Andre0512/pyhOn.git
synced 2025-05-28 13:44:13 -04:00
Improve cmd tool, write README
This commit is contained in:
parent
22276832cd
commit
993a4c1d79
5 changed files with 80 additions and 21 deletions
|
@ -18,30 +18,46 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
def get_arguments():
|
||||
"""Get parsed arguments."""
|
||||
parser = argparse.ArgumentParser(description="hOn: Command Line Utility")
|
||||
parser.add_argument("-u", "--user", help="user of haier hOn account")
|
||||
parser.add_argument("-p", "--password", help="password of haier hOn account")
|
||||
parser = argparse.ArgumentParser(description="pyhOn: Command Line Utility")
|
||||
parser.add_argument("-u", "--user", help="user for haier hOn account")
|
||||
parser.add_argument("-p", "--password", help="password for haier hOn account")
|
||||
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():
|
||||
args = get_arguments()
|
||||
if not (user := args["user"]):
|
||||
user = input("User of hOn account: ")
|
||||
user = input("User for hOn account: ")
|
||||
if not (password := args["password"]):
|
||||
password = getpass("Password of hOn account: ")
|
||||
password = getpass("Password for hOn account: ")
|
||||
async with HonConnection(user, password) as hon:
|
||||
await hon.setup()
|
||||
for device in hon.devices:
|
||||
print(10 * "=", device.nick_name, 10 * "=")
|
||||
print(10 * "-", "attributes", 10 * "-")
|
||||
pprint(device.attributes)
|
||||
print(10 * "-", "statistics", 10 * "-")
|
||||
pprint(device.statistics)
|
||||
print(10 * "-", "commands", 10 * "-")
|
||||
pprint(device.parameters)
|
||||
print(10 * "-", "settings", 10 * "-")
|
||||
pprint(device.settings)
|
||||
print("=" * 10, device.nick_name, "=" * 10)
|
||||
pretty_print({"commands": device.commands})
|
||||
pretty_print({"data": device.data})
|
||||
|
||||
|
||||
def start():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue