-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
52 lines (42 loc) · 1.42 KB
/
example.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
from src.pyowletapi.api import OwletAPI
from src.pyowletapi.sock import Sock
from src.pyowletapi.exceptions import (
OwletAuthenticationError,
OwletConnectionError,
OwletError,
OwletPasswordError,
OwletEmailError,
)
import asyncio
import json
async def run():
with open("login.json") as file:
data = json.load(file)
region = data["region"]
username = data["username"]
password = data["password"]
api = OwletAPI(
region, username, password)
try:
await api.authenticate()
devices = await api.get_devices()
#print(devices)
socks = {
device["device"]["dsn"]: Sock(api, device["device"]) for device in devices['response']
}
for sock in socks.values():
#print(await sock._api.get_properties(sock.serial))
properties = await sock.update_properties()
print(sock.revision)
properties = properties["properties"]
print(properties)
print(await sock.control_base_station(True))
# print(properties['heart_rate'], properties['oxygen_saturation'], properties['battery_percentage'])
except (OwletEmailError, OwletPasswordError, OwletError) as err:
print(err)
await api.close()
exit()
await api.close()
if __name__ == "__main__":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(run())