-
Notifications
You must be signed in to change notification settings - Fork 18
/
test_async.py
51 lines (36 loc) · 1.16 KB
/
test_async.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
import asyncio
import datetime
import json
import time
from os import environ
from pyworxcloud import WorxCloud
from pyworxcloud.events import LandroidEvent
from pyworxcloud.utils import DeviceHandler
EMAIL = environ["EMAIL"]
PASS = environ["PASSWORD"]
TYPE = environ["TYPE"]
tz = datetime.datetime.now().astimezone().tzinfo.tzname(None)
async def main():
loop = asyncio.get_running_loop()
await async_worx()
async def async_worx():
# Clear the screen for better visibility when debugging
# Initialize the class and connect
cloud = WorxCloud(EMAIL, PASS, TYPE)
cloud.authenticate()
cloud.connect()
cloud.set_callback(LandroidEvent.DATA_RECEIVED, receive_data)
## Force an data update
# device = cloud.devices[environ["DEV_NAME"]]
# cloud.update(device.serial_number)
print("Listening for new data")
while 1:
pass
# Self explanatory - disconnect from the cloud
cloud.disconnect()
def receive_data(
name: str, device: DeviceHandler # pylint: disable=unused-argument
) -> None:
"""Callback function when the MQTT broker sends new data."""
print("Got data on MQTT from " + name)
asyncio.run(main())