forked from marconfus/aionefit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_client.py
52 lines (41 loc) · 1.46 KB
/
example_client.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 aionefit import NefitCore
import asyncio
from pprint import pprint
import logging
from secrets import SERIAL_NUMBER, ACCESS_KEY, PASSWORD
async def main(loop):
def parse_recursive(msg):
if 'type' in msg and msg['type'] == 'refEnum':
for reference in msg['references']:
client.get(reference['id'])
else:
pprint(msg)
async def parse_message(msg):
pprint(msg)
client = NefitCore(serial_number=SERIAL_NUMBER,
access_key=ACCESS_KEY,
password=PASSWORD,
message_callback=parse_message)
await client.connect()
loop.nefitclient = client
await client.xmppclient.connected_event.wait()
client.get('/ecus/rrc/uiStatus')
# await client.xmppclient.message_event.wait()
# client.put_value('/heatingCircuits/hc1/usermode', 'clock')
# client.set_temperature(22)
# client.get('/heatingCircuits/hc1/manualTempOverride/status')
# client.get('/')
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG,
format='%(levelname)-8s %(module)s/%(funcName)s : ' +
'%(message)s')
logging.getLogger('aionefit').setLevel(logging.DEBUG)
loop = asyncio.get_event_loop()
try:
asyncio.ensure_future(main(loop))
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.nefitclient.disconnect()
loop.close()