-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_api_use.py
74 lines (55 loc) · 2.53 KB
/
example_api_use.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import asyncio
import json
import logging
import sys
from aiodabpumps import DabPumpsApi
# Setup logging to StdOut
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger(__name__)
TEST_USERNAME = "fill in your DConnect username here"
TEST_PASSWORD = "fill in your DConnect password here"
#
# Comment out the line below if username and password are set above
from tests import TEST_USERNAME, TEST_PASSWORD
async def main():
api = None
try:
# Process these calls in the right order
api = DabPumpsApi(TEST_USERNAME, TEST_PASSWORD)
await api.async_login()
# Retrieve installations accessible by this user
install_map = await api.async_fetch_install_list()
logger.info(f"installs: {len(install_map)}")
for install_id, install in install_map.items():
logger.info("")
logger.info(f"installation: {install.name} ({install.id})")
# Retrieve installation details
device_map = await api.async_fetch_install_details(install_id)
logger.info(f"devices: {len(device_map)}")
for device_serial in device_map.keys():
device = await api.async_fetch_device_details(device_serial)
logger.info("")
logger.info(f"device: {device.name} ({device.serial})")
for k,v in device._asdict().items():
logger.info(f" {k}: {v}")
# Retrieve device config details
config_id = device.config_id
config = await api.async_fetch_device_config(config_id)
logger.info("")
logger.info(f"config: {config.description} ({config.id})")
logger.info(f" meta_params: {len(config.meta_params)}")
for k,v in config.meta_params.items():
logger.info(f" {k}: {v}")
# Once the calls above have been perfomed, the call below can be repeated periodically
# Retrieve device statusses
status_map = await api.async_fetch_device_statusses(device_serial)
logger.info("")
logger.info(f"statusses: {len(status_map)}")
for k,v in status_map.items():
logger.info(f" {v.key}: {v.val}")
except Exception as e:
logger.info(f"Unexpected exception: {e}")
finally:
if api:
await api.async_close()
asyncio.run(main()) # main loop