-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.py
executable file
·46 lines (32 loc) · 1.08 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
#!/usr/bin/env python3
import asyncio
import os
from httpx import AsyncClient
from dotenv import load_dotenv
from src.vaillant_netatmo_api import AuthClient, ThermostatClient, TokenStore, Token
load_dotenv()
client_id = os.environ['CLIENT_ID']
client_secret = os.environ['CLIENT_SECRET']
access_token = os.environ['ACCESS_TOKEN']
refresh_token = os.environ['REFRESH_TOKEN']
async def main():
async with AsyncClient() as client:
token_store = TokenStore(
client_id,
client_secret,
Token({
"access_token": access_token,
"refresh_token": refresh_token,
}),
handle_token_update
)
await async_call_api(client, token_store)
def handle_token_update(token):
print(token.access_token)
print(token.refresh_token)
async def async_call_api(client, token_store):
client = ThermostatClient(client, token_store)
devices = await client.async_get_thermostats_data()
print(devices[0].modules[0].measured.temperature)
if __name__ == "__main__":
asyncio.run(main())