Skip to content

Commit

Permalink
Merge 0279dff into 5957eb0
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio committed Dec 10, 2020
2 parents 5957eb0 + 0279dff commit cf520fd
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 162 deletions.
6 changes: 2 additions & 4 deletions examples/example_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ async def main():
gateway_port=gateway.port,
)

await tunnel.connect_udp()
await tunnel.connect()
await tunnel.start()

await tunnel.send_telegram(
Telegram(
Expand All @@ -53,8 +52,7 @@ async def main():
)
await asyncio.sleep(2)

await tunnel.connectionstate()
await tunnel.disconnect()
await tunnel.stop()


asyncio.run(main())
4 changes: 2 additions & 2 deletions test/io_tests/tunnel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def tearDown(self):
"""Tear down test class."""
self.loop.close()

@patch("xknx.io.Tunnel.send_ack")
@patch("xknx.io.Tunnel._send_tunnelling_ack")
def test_tunnel_request_received(self, send_ack_mock):
"""Test Tunnel for calling send_ack on normal frames."""
# LDataInd GroupValueWrite from 1.1.22 to to 5/1/22 with DPT9 payload 0C 3F
Expand All @@ -47,7 +47,7 @@ def test_tunnel_request_received(self, send_ack_mock):
self.tg_received_mock.assert_called_once_with(telegram)
send_ack_mock.assert_called_once_with(0x02, 0x21)

@patch("xknx.io.Tunnel.send_ack")
@patch("xknx.io.Tunnel._send_tunnelling_ack")
def test_tunnel_request_received_unsupported_frames(self, send_ack_mock):
"""Test Tunnel sending ACK for unsupported frames."""
# LDataInd APciPhysAddrRead from 0.0.1 to 0/0/0 broadcast - ETS scan for devices in programming mode
Expand Down
8 changes: 7 additions & 1 deletion xknx/io/connectionstate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Abstraction to send ConnectonStateRequest and wait for ConnectionStateResponse."""
from xknx.knxip import HPAI, ConnectionStateRequest, ConnectionStateResponse, KNXIPFrame

from .const import CONNECTIONSTATE_REQUEST_TIMEOUT
from .request_response import RequestResponse


Expand All @@ -10,7 +11,12 @@ class ConnectionState(RequestResponse):
def __init__(self, xknx, udp_client, communication_channel_id):
"""Initialize ConnectionState class."""
self.udp_client = udp_client
super().__init__(xknx, self.udp_client, ConnectionStateResponse)
super().__init__(
xknx,
self.udp_client,
ConnectionStateResponse,
timeout_in_seconds=CONNECTIONSTATE_REQUEST_TIMEOUT,
)
self.communication_channel_id = communication_channel_id

def create_knxipframe(self) -> KNXIPFrame:
Expand Down
4 changes: 4 additions & 0 deletions xknx/io/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@

DEFAULT_MCAST_GRP = "224.0.23.12"
DEFAULT_MCAST_PORT = 3671

CONNECTION_ALIVE_TIME = 120
CONNECTIONSTATE_REQUEST_TIMEOUT = 10
HEARTBEAT_RATE = CONNECTION_ALIVE_TIME - (CONNECTIONSTATE_REQUEST_TIMEOUT * 5)
2 changes: 2 additions & 0 deletions xknx/io/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ async def send_knxipframe(self, knxipframe):
async def start(self):
"""Start routing."""
await self.udpclient.connect()
self.xknx.connected.set()

async def stop(self):
"""Stop routing."""
await self.udpclient.stop()
self.xknx.connected.clear()
Loading

0 comments on commit cf520fd

Please sign in to comment.