Skip to content

Commit

Permalink
Dump data dictionary skeleton (#11)
Browse files Browse the repository at this point in the history
- Updated 015-000 dump
  • Loading branch information
oyvindwe authored Jul 14, 2024
1 parent bb1178c commit 49b81d0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Licensed under [GPLv3](LICENSE).
To test out the library:
```bash
pip install connectlife
python -m connectlife.dump <username> <password>
python -m connectlife.dump --username <username> --pasword <password>
```

This will log in to the ConnectLife API using the provided username and password, and print the list of all fields
Expand Down
63 changes: 42 additions & 21 deletions connectlife/dump.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import asyncio
from getpass import getpass
import logging
import json
import sys
Expand All @@ -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"] = "<redacted>"
appliance["puid"] = "<redacted>"
appliance["wifiId"] = "<redacted>"
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))
12 changes: 10 additions & 2 deletions dumps/015-000.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
"deviceNickName": "ASKO dishwasher",
"deviceTypeCode": "015",
"deviceTypeName": "",
"offlineState": 1,
"offlineState": 0,
"puid": "<redacted>",
"role": 1,
"roomId": 1044366,
"roomName": "Kj\u00f8kken",
"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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 49b81d0

Please sign in to comment.