forked from rxwen/python-terncy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
41 lines (31 loc) · 978 Bytes
/
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import terncy
def event_hander(t, msg):
print("got event", msg)
async def main():
await terncy.start_discovery()
await asyncio.sleep(2)
await terncy.start_discovery()
print(terncy.discovered_homecenters)
# construct a Terncy object from discovered info
t = terncy.Terncy(
"client_id",
"box-12-34-56-78-90-ab",
"192.168.1.187",
443,
"homeassistant_user",
"",
)
token_id, token = await t.request_token("homeassistant_user", "HA User")
# approve the token request in Terncy app, the client should store the
# allocated token and token id for later usage
# create a new Terncy object with approved token
t.token = token
t.token_id = token_id
t.register_event_handler(event_hander)
await t.start()
t.set_onoff("devid_of_device", 1)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())