mirror of
https://github.com/Andre0512/pyhOn.git
synced 2025-05-15 07:34:26 -04:00
Add more type hints
This commit is contained in:
parent
ad0d065b03
commit
9eb99f283b
30 changed files with 392 additions and 243 deletions
|
@ -6,16 +6,17 @@ import logging
|
|||
import sys
|
||||
from getpass import getpass
|
||||
from pathlib import Path
|
||||
from typing import Tuple, Dict, Any
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from pyhon import Hon, HonAPI, helper, diagnose
|
||||
from pyhon import Hon, HonAPI, diagnose, printer
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_arguments():
|
||||
def get_arguments() -> Dict[str, Any]:
|
||||
"""Get parsed arguments."""
|
||||
parser = argparse.ArgumentParser(description="pyhOn: Command Line Utility")
|
||||
parser.add_argument("-u", "--user", help="user for haier hOn account")
|
||||
|
@ -39,7 +40,7 @@ def get_arguments():
|
|||
return vars(parser.parse_args())
|
||||
|
||||
|
||||
async def translate(language, json_output=False):
|
||||
async def translate(language: str, json_output: bool = False) -> None:
|
||||
async with HonAPI(anonymous=True) as hon:
|
||||
keys = await hon.translation_keys(language)
|
||||
if json_output:
|
||||
|
@ -52,10 +53,10 @@ async def translate(language, json_output=False):
|
|||
.replace("\\r", "")
|
||||
)
|
||||
keys = json.loads(clean_keys)
|
||||
print(helper.pretty_print(keys))
|
||||
print(printer.pretty_print(keys))
|
||||
|
||||
|
||||
def get_login_data(args):
|
||||
def get_login_data(args: Dict[str, str]) -> Tuple[str, str]:
|
||||
if not (user := args["user"]):
|
||||
user = input("User for hOn account: ")
|
||||
if not (password := args["password"]):
|
||||
|
@ -63,44 +64,44 @@ def get_login_data(args):
|
|||
return user, password
|
||||
|
||||
|
||||
async def main():
|
||||
async def main() -> None:
|
||||
args = get_arguments()
|
||||
if language := args.get("translate"):
|
||||
await translate(language, json_output=args.get("json"))
|
||||
await translate(language, json_output=args.get("json", ""))
|
||||
return
|
||||
async with Hon(*get_login_data(args)) as hon:
|
||||
for device in hon.appliances:
|
||||
if args.get("export"):
|
||||
anonymous = args.get("anonymous", False)
|
||||
path = Path(args.get("directory"))
|
||||
path = Path(args.get("directory", "."))
|
||||
if not args.get("zip"):
|
||||
for file in await diagnose.appliance_data(device, path, anonymous):
|
||||
print(f"Created {file}")
|
||||
else:
|
||||
file = await diagnose.zip_archive(device, path, anonymous)
|
||||
print(f"Created {file}")
|
||||
archive = await diagnose.zip_archive(device, path, anonymous)
|
||||
print(f"Created {archive}")
|
||||
continue
|
||||
print("=" * 10, device.appliance_type, "-", device.nick_name, "=" * 10)
|
||||
if args.get("keys"):
|
||||
data = device.data.copy()
|
||||
attr = "get" if args.get("all") else "pop"
|
||||
print(
|
||||
helper.key_print(
|
||||
printer.key_print(
|
||||
data["attributes"].__getattribute__(attr)("parameters")
|
||||
)
|
||||
)
|
||||
print(helper.key_print(data.__getattribute__(attr)("appliance")))
|
||||
print(helper.key_print(data))
|
||||
print(printer.key_print(data.__getattribute__(attr)("appliance")))
|
||||
print(printer.key_print(data))
|
||||
print(
|
||||
helper.pretty_print(
|
||||
helper.create_command(device.commands, concat=True)
|
||||
printer.pretty_print(
|
||||
printer.create_command(device.commands, concat=True)
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(diagnose.yaml_export(device))
|
||||
|
||||
|
||||
def start():
|
||||
def start() -> None:
|
||||
try:
|
||||
asyncio.run(main())
|
||||
except KeyboardInterrupt:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue