diff --git a/README.md b/README.md index 643bf67..708641e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Licensed under [GPLv3](LICENSE). To test out the library: ```bash pip install connectlife -python -m connectlife.dump +python -m connectlife.dump --username --pasword ``` This will log in to the ConnectLife API using the provided username and password, and print the list of all fields diff --git a/connectlife/dump.py b/connectlife/dump.py index 77b8c7f..16ba15f 100644 --- a/connectlife/dump.py +++ b/connectlife/dump.py @@ -1,5 +1,6 @@ import argparse import asyncio +from getpass import getpass import logging import json import sys @@ -12,32 +13,52 @@ def order_dict(dictionary): for k, v in sorted(dictionary.items())} -async def main(): - parser = argparse.ArgumentParser( - prog="dump", - description="Connects to the ConnectLife API and prints the response to the '/appliances' request") - parser.add_argument("username") - parser.add_argument("password") - args = parser.parse_args() - - api = ConnectLifeApi(args.username, args.password) +async def main(username: str, password: str, format: str): + api = ConnectLifeApi(username, password) appliances = await api.get_appliances_json() # Redact private fields for appliance in appliances: appliance["deviceId"] = "" appliance["puid"] = "" appliance["wifiId"] = "" - for a in appliances: - with open(f'{a["deviceTypeCode"]}-{a["deviceFeatureCode"]}.json', 'w') as f: - json.dump(a, f, indent=2) + if format == "json": + with open(f'{appliance["deviceTypeCode"]}-{appliance["deviceFeatureCode"]}.json', 'w') as f: + json.dump(order_dict(appliance), f, indent=2) + if format == "dd": + with open(f'{appliance["deviceTypeCode"]}-{appliance["deviceFeatureCode"]}.yaml', 'w') as f: + f.write(f'# {appliance["deviceNickName"]}\n') + f.write('properties:\n') + for k, v in sorted(appliance["statusList"].items()): + f.write(f'- property: {k}\n') + f.write(f' # Sample value: {v}\n') + if __name__ == "__main__": - logger = logging.getLogger("connectlife") - logger.setLevel(logging.DEBUG) - handler = logging.StreamHandler(sys.stderr) - handler.setLevel(logging.DEBUG) - formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') - handler.setFormatter(formatter) - logger.addHandler(handler) - - asyncio.run(main()) + parser = argparse.ArgumentParser( + prog="dump", + description="Connects to the ConnectLife API and writes a file for each appliance") + parser.add_argument("-u", "--username") + parser.add_argument("-p", "--password") + parser.add_argument( + "-f", + "--format", + choices={ + "json": "Dump to JSON file", + "dd": "Create data dictionary skeleton" + }, + default="json" + ) + parser.add_argument("-v", "--verbose", action='store_true') + args = parser.parse_args() + username = args.username if args.username else input("Username: ") + password = args.password if args.password else getpass() + if args.verbose: + logger = logging.getLogger("connectlife") + logger.setLevel(logging.DEBUG) + handler = logging.StreamHandler(sys.stdout) + handler.setLevel(logging.DEBUG) + formatter = logging.Formatter('%(message)s') + handler.setFormatter(formatter) + logger.addHandler(handler) + + asyncio.run(main(username, password, args.format)) diff --git a/dumps/015-000.json b/dumps/015-000.json index 5c1428d..226046f 100644 --- a/dumps/015-000.json +++ b/dumps/015-000.json @@ -7,7 +7,7 @@ "deviceNickName": "ASKO dishwasher", "deviceTypeCode": "015", "deviceTypeName": "", - "offlineState": 1, + "offlineState": 0, "puid": "", "role": 1, "roomId": 1044366, @@ -15,7 +15,13 @@ "seq": 0, "statusList": { "ADO_allowed": "1", - "Alarm_auto_dose_refill": "1", + "Alarm_Autodose_level10": "0", + "Alarm_Autodose_level20": "0", + "Alarm_External_autodose_level15": "0", + "Alarm_External_autodose_level30": "0", + "Alarm_Rinse_aid_refill_external": "0", + "Alarm_Sani_program_finished": "0", + "Alarm_auto_dose_refill": "0", "Alarm_clean_the_filters": "1", "Alarm_door_closed": "1", "Alarm_door_opened": "1", @@ -35,6 +41,7 @@ "Curent_program_duration": "131", "Curent_program_remaining_time": "86", "Current_program_phase": "7", + "Current_temperature": "0", "Delay_start": "1", "Delay_start_remaining_time": "0", "Delay_start_set_time": "0", @@ -115,6 +122,7 @@ "Session_pairing_status": "0", "Silence_on_demand": "0", "Silence_on_demand_allowed": "0", + "Smart_Dry_function": "0", "Soft_pairing_status": "0", "Speed_on_demand": "1", "Spend_on_demand_allowed": "3",