|
1 | 1 | """Run an example script to quickly test any MyQ account."""
|
2 | 2 | import asyncio
|
3 | 3 | import logging
|
| 4 | +import json |
4 | 5 |
|
5 | 6 | from aiohttp import ClientSession
|
6 | 7 |
|
|
20 | 21 | MYQ_BRAND = '<BRAND>'
|
21 | 22 | LOGLEVEL = 'ERROR'
|
22 | 23 |
|
| 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 | + |
23 | 30 |
|
24 | 31 | async def main() -> None:
|
25 | 32 | """Create the aiohttp session and run the example."""
|
@@ -50,39 +57,42 @@ async def main() -> None:
|
50 | 57 | print('Unattended Close: {0}'.format(device.close_allowed))
|
51 | 58 | print()
|
52 | 59 | 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) |
78 | 76 | await device.update()
|
79 |
| - print(' {} Current State: {}'.format( |
80 |
| - waited, device.state)) |
| 77 | + print() |
| 78 | + print('Current State: {0}'.format(device.state)) |
81 | 79 |
|
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)) |
86 | 96 | except MyQError as err:
|
87 | 97 | print(err)
|
88 | 98 |
|
|
0 commit comments