Skip to content

Commit

Permalink
ConnectRequest failed: add status code
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio committed Dec 25, 2020
1 parent 7763f1d commit 2a75c3f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion xknx/io/request_response.py
Expand Up @@ -5,7 +5,7 @@
"""
import asyncio
import logging
from typing import TYPE_CHECKING, Type
from typing import TYPE_CHECKING, Optional, Type

from xknx.knxip import ErrorCode, KNXIPBodyResponse, KNXIPFrame

Expand Down Expand Up @@ -35,6 +35,8 @@ def __init__(
self.success = False
self.timeout_in_seconds = timeout_in_seconds

self.response_status_code: Optional[ErrorCode] = None

def create_knxipframe(self) -> KNXIPFrame:
"""Create KNX/IP Frame object to be sent to device."""
raise NotImplementedError("create_knxipframe has to be implemented")
Expand Down Expand Up @@ -70,6 +72,7 @@ def response_rec_callback(self, knxipframe: KNXIPFrame, _: UDPClient) -> None:
if not isinstance(knxipframe.body, self.awaited_response_class):
logger.warning("Could not understand knxipframe")
return
self.response_status_code = knxipframe.body.status_code
self.response_received_or_timeout.set()
if knxipframe.body.status_code == ErrorCode.E_NO_ERROR:
self.success = True
Expand Down
4 changes: 3 additions & 1 deletion xknx/io/tunnel.py
Expand Up @@ -170,7 +170,9 @@ async def _connect_request(self) -> bool:
connect.identifier,
)
return True
raise CommunicationError("ConnectRequest failed")
raise CommunicationError(
f"ConnectRequest failed. Status code: {connect.response_status_code}"
)

async def _connectionstate_request(self) -> bool:
"""Return state of tunnel. True if tunnel is in good shape."""
Expand Down

0 comments on commit 2a75c3f

Please sign in to comment.