-
-
Notifications
You must be signed in to change notification settings - Fork 117
Enhance Interface ABC with common connection management #1803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matssun
wants to merge
3
commits into
XKNX:main
Choose a base branch
from
matssun:feat/enhance-interface-abstract
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−36
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| from contextlib import asynccontextmanager | ||
| import logging | ||
| import random | ||
| from typing import TYPE_CHECKING, Final | ||
| from typing import TYPE_CHECKING, ClassVar, Final | ||
|
|
||
| from xknx.cemi import CEMIFrame, CEMIMessageCode | ||
| from xknx.core import XknxConnectionState, XknxConnectionType | ||
|
|
@@ -147,15 +147,13 @@ class Routing(Interface): | |
|
|
||
| __slots__ = ( | ||
| "_flow_control", | ||
| "cemi_received_callback", | ||
| "individual_address", | ||
| "local_ip", | ||
| "multicast_group", | ||
| "multicast_port", | ||
| "xknx", | ||
| ) | ||
|
|
||
| connection_type = XknxConnectionType.ROUTING | ||
| connection_type: ClassVar[XknxConnectionType] = XknxConnectionType.ROUTING | ||
| transport: UDPTransport | ||
|
|
||
| def __init__( | ||
|
|
@@ -202,10 +200,8 @@ def _init_transport(self) -> None: | |
|
|
||
| async def connect(self) -> None: | ||
| """Start routing.""" | ||
| self.xknx.current_address = self.individual_address | ||
| self.xknx.connection_manager.connection_state_changed( | ||
| XknxConnectionState.CONNECTING, self.connection_type | ||
| ) | ||
| self.current_address = self.individual_address | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should use the new method now |
||
| self.connection_state_changed(XknxConnectionState.CONNECTING) | ||
| try: | ||
| await self.transport.connect() | ||
| except OSError as ex: | ||
|
|
@@ -214,20 +210,16 @@ async def connect(self) -> None: | |
| type(ex).__name__, | ||
| ex, | ||
| ) | ||
| self.xknx.connection_manager.connection_state_changed( | ||
| XknxConnectionState.DISCONNECTED | ||
| ) | ||
| self.connection_state_changed(XknxConnectionState.DISCONNECTED) | ||
| # close udp transport to prevent open file descriptors | ||
| self.transport.stop() | ||
| raise CommunicationError("Routing could not be started") from ex | ||
| self.xknx.connection_manager.connection_state_changed( | ||
| XknxConnectionState.CONNECTED, self.connection_type | ||
| ) | ||
| self.connection_state_changed(XknxConnectionState.CONNECTED) | ||
|
|
||
| async def disconnect(self) -> None: | ||
| """Stop routing.""" | ||
| self.transport.stop() | ||
| self.xknx.connection_manager.connection_state_changed( | ||
| self.connection_state_changed( | ||
| XknxConnectionState.DISCONNECTED | ||
| ) | ||
| self._flow_control.cancel() | ||
|
|
@@ -290,7 +282,7 @@ class SecureRouting(Routing): | |
| "latency_ms", | ||
| ) | ||
|
|
||
| connection_type = XknxConnectionType.ROUTING_SECURE | ||
| connection_type: ClassVar[XknxConnectionType] = XknxConnectionType.ROUTING_SECURE | ||
| transport: SecureGroup | ||
|
|
||
| def __init__( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| from collections.abc import AsyncGenerator | ||
| from contextlib import asynccontextmanager | ||
| import logging | ||
| from typing import TYPE_CHECKING | ||
| from typing import TYPE_CHECKING, ClassVar | ||
|
|
||
| from xknx.cemi import CEMIFrame | ||
| from xknx.core import XknxConnectionState, XknxConnectionType | ||
|
|
@@ -55,14 +55,12 @@ class _Tunnel(Interface): | |
| "_src_address", | ||
| "auto_reconnect", | ||
| "auto_reconnect_wait", | ||
| "cemi_received_callback", | ||
| "communication_channel", | ||
| "local_hpai", | ||
| "sequence_number", | ||
| "xknx", | ||
| ) | ||
|
|
||
| connection_type: XknxConnectionType | ||
| connection_type: ClassVar[XknxConnectionType] | ||
| transport: KNXIPTransport | ||
|
|
||
| def __init__( | ||
|
|
@@ -119,9 +117,7 @@ async def connect(self) -> None: | |
|
|
||
| Raise CommunicationError when not successful. | ||
| """ | ||
| self.xknx.connection_manager.connection_state_changed( | ||
| XknxConnectionState.CONNECTING, self.connection_type | ||
| ) | ||
| self.connection_state_changed(XknxConnectionState.CONNECTING) | ||
| try: | ||
| await self.transport.connect() | ||
| await self.setup_tunnel() | ||
|
|
@@ -132,19 +128,15 @@ async def connect(self) -> None: | |
| type(ex).__name__, | ||
| ex, | ||
| ) | ||
| self.xknx.connection_manager.connection_state_changed( | ||
| XknxConnectionState.DISCONNECTED | ||
| ) | ||
| self.connection_state_changed(XknxConnectionState.DISCONNECTED) | ||
| # close transport to prevent open file descriptors | ||
| self.transport.stop() | ||
| raise CommunicationError( | ||
| "Tunnel connection could not be established" | ||
| ) from ex | ||
|
|
||
| self._tunnel_established() | ||
| self.xknx.connection_manager.connection_state_changed( | ||
| XknxConnectionState.CONNECTED, self.connection_type | ||
| ) | ||
| self.connection_state_changed(XknxConnectionState.CONNECTED) | ||
|
|
||
| def _tunnel_established(self) -> None: | ||
| """Set up interface when the tunnel is ready.""" | ||
|
|
@@ -209,7 +201,7 @@ async def _reconnect(self) -> None: | |
| def _prepare_disconnect(self) -> None: | ||
| """Prepare for disconnect. Stop tunnel related tasks and set connection state.""" | ||
| self.stop_heartbeat() | ||
| self.xknx.connection_manager.connection_state_changed( | ||
| self.connection_state_changed( | ||
| XknxConnectionState.DISCONNECTED | ||
| ) | ||
|
|
||
|
|
@@ -251,7 +243,7 @@ async def _connect_request(self) -> bool: | |
| ) | ||
| # Use the individual address provided by the tunnelling server | ||
| self._src_address = connect.crd.individual_address or IndividualAddress(0) | ||
| self.xknx.current_address = self._src_address | ||
| self.current_address = self._src_address | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should use the new method now |
||
| logger.debug( | ||
| "Tunnel established. communication_channel=%s, address=%s", | ||
| connect.communication_channel, | ||
|
|
@@ -456,7 +448,7 @@ class UDPTunnel(_Tunnel): | |
| "route_back", | ||
| ) | ||
|
|
||
| connection_type = XknxConnectionType.TUNNEL_UDP | ||
| connection_type: ClassVar[XknxConnectionType] = XknxConnectionType.TUNNEL_UDP | ||
| transport: UDPTransport | ||
|
|
||
| def __init__( | ||
|
|
@@ -700,7 +692,7 @@ class TCPTunnel(_Tunnel): | |
|
|
||
| __slots__ = ("gateway_ip", "gateway_port") | ||
|
|
||
| connection_type = XknxConnectionType.TUNNEL_TCP | ||
| connection_type: ClassVar[XknxConnectionType] = XknxConnectionType.TUNNEL_TCP | ||
| transport: TCPTransport | ||
|
|
||
| def __init__( | ||
|
|
@@ -746,7 +738,7 @@ class SecureTunnel(TCPTunnel): | |
|
|
||
| __slots__ = ("_device_authentication_password", "_user_id", "_user_password") | ||
|
|
||
| connection_type = XknxConnectionType.TUNNEL_SECURE | ||
| connection_type: ClassVar[XknxConnectionType] = XknxConnectionType.TUNNEL_SECURE | ||
| transport: SecureSession | ||
|
|
||
| def __init__( | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.