Skip to content

Commit ad206fe

Browse files
committed
Added easy way to dump information retrieved
Added an easier method to dump the JSON info received from MyQ using the example.py.
1 parent 89969be commit ad206fe

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

example.py

+41-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Run an example script to quickly test any MyQ account."""
22
import asyncio
33
import logging
4+
import json
45

56
from aiohttp import ClientSession
67

@@ -20,6 +21,12 @@
2021
MYQ_BRAND = '<BRAND>'
2122
LOGLEVEL = 'ERROR'
2223

24+
# Set JSON_DUMP to True to dump all the device information retrieved,
25+
# this can be helpful to determine what else is available.
26+
# Set JSON_DUMP to False to open/close the doors instead. i.e.:
27+
# JSON_DUMP = False
28+
JSON_DUMP = True
29+
2330

2431
async def main() -> None:
2532
"""Create the aiohttp session and run the example."""
@@ -50,39 +57,42 @@ async def main() -> None:
5057
print('Unattended Close: {0}'.format(device.close_allowed))
5158
print()
5259
print('Current State: {0}'.format(device.state))
53-
if device.state != STATE_OPEN:
54-
print('Opening the device...')
55-
await device.open()
56-
print(' 0 Current State: {0}'.format(device.state))
57-
for waited in range(1, 30):
58-
if device.state == STATE_OPEN:
59-
break
60-
await asyncio.sleep(1)
61-
await device.update()
62-
print(' {} Current State: {}'.format(
63-
waited, device.state))
64-
65-
await asyncio.sleep(10)
66-
await device.update()
67-
print()
68-
print('Current State: {0}'.format(device.state))
69-
70-
if device.state != STATE_CLOSED:
71-
print('Closing the device...')
72-
await device.close()
73-
print(' 0 Current State: {0}'.format(device.state))
74-
for waited in range(1, 30):
75-
if device.state == STATE_CLOSED:
76-
break
77-
await asyncio.sleep(1)
60+
if JSON_DUMP:
61+
print(json.dumps(device._device, indent=4))
62+
else:
63+
if device.state != STATE_OPEN:
64+
print('Opening the device...')
65+
await device.open()
66+
print(' 0 Current State: {0}'.format(device.state))
67+
for waited in range(1, 30):
68+
if device.state == STATE_OPEN:
69+
break
70+
await asyncio.sleep(1)
71+
await device.update()
72+
print(' {} Current State: {}'.format(
73+
waited, device.state))
74+
75+
await asyncio.sleep(10)
7876
await device.update()
79-
print(' {} Current State: {}'.format(
80-
waited, device.state))
77+
print()
78+
print('Current State: {0}'.format(device.state))
8179

82-
await asyncio.sleep(10)
83-
await device.update()
84-
print()
85-
print('Current State: {0}'.format(device.state))
80+
if device.state != STATE_CLOSED:
81+
print('Closing the device...')
82+
await device.close()
83+
print(' 0 Current State: {0}'.format(device.state))
84+
for waited in range(1, 30):
85+
if device.state == STATE_CLOSED:
86+
break
87+
await asyncio.sleep(1)
88+
await device.update()
89+
print(' {} Current State: {}'.format(
90+
waited, device.state))
91+
92+
await asyncio.sleep(10)
93+
await device.update()
94+
print()
95+
print('Current State: {0}'.format(device.state))
8696
except MyQError as err:
8797
print(err)
8898

0 commit comments

Comments
 (0)