-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws02.py
49 lines (32 loc) · 798 Bytes
/
ws02.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
#!/usr/bin/python3
# ws02.py
# 202101081021
#
# simple web socket interface to Home Assistant ZHA web socket
# loops forever getting current zigbee devices and their attributes in JSON format
import sys
import json
import time
from websocket import create_connection
ACCESS_TOKEN = ""
ws = create_connection("ws://localhost:8123/api/websocket")
result = ws.recv()
ws.send(json.dumps(
{'type': 'auth',
'access_token': ACCESS_TOKEN}
))
result = ws.recv()
ident = 1
try:
while True :
ws.send(json.dumps(
{'id': ident, 'type': 'zha/devices'}
))
result = ws.recv()
print(result)
# print(80 * "-")
time.sleep( 5 )
ident = ident + 1
except KeyboardInterrupt :
sys.exit(0)
# # EOF