-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
example_disconnect.py
45 lines (29 loc) · 1.18 KB
/
example_disconnect.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
"""Example on how to disconnect/reset all available tunneling channels."""
import asyncio
from xknx import XKNX
from xknx.io import GatewayScanner, UDPClient
from xknx.io.request_response import ConnectionState, Disconnect
async def main():
"""Search for a Tunnelling device, walk through all possible channels and disconnect them."""
xknx = XKNX()
gatewayscanner = GatewayScanner(xknx)
gateways = await gatewayscanner.scan()
if not gateways:
print("No Gateways found")
return
gateway = gateways[0]
if not gateway.supports_tunnelling:
print("Gateway does not support tunneling")
return
udp_client = UDPClient(xknx, (gateway.local_ip, 0), (gateway.ip_addr, gateway.port))
await udp_client.connect()
for i in range(0, 255):
conn_state = ConnectionState(xknx, udp_client, communication_channel_id=i)
await conn_state.start()
if conn_state.success:
print("Disconnecting ", i)
disconnect = Disconnect(xknx, udp_client, communication_channel_id=i)
await disconnect.start()
if disconnect.success:
print("Disconnected ", i)
asyncio.run(main())