Skip to content

Commit 4c35053

Browse files
Disconnect when we get an IncompleteReadError
1 parent d8c37a4 commit 4c35053

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

aiocomfoconnect/bridge.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async def _connect(self, uuid: str):
9595
self._reader, self._writer = await asyncio.wait_for(asyncio.open_connection(self.host, self.PORT), TIMEOUT)
9696
except asyncio.TimeoutError as exc:
9797
_LOGGER.warning("Timeout while connecting to bridge %s", self.host)
98-
raise AioComfoConnectTimeout() from exc
98+
raise AioComfoConnectTimeout from exc
9999

100100
self._reference = 1
101101
self._local_uuid = uuid
@@ -122,12 +122,9 @@ async def _read_messages():
122122

123123
async def _disconnect(self):
124124
"""Disconnect from the bridge."""
125-
_LOGGER.debug("Disconnecting from bridge %s", self.host)
126-
127125
if self._writer:
128126
self._writer.close()
129-
130-
_LOGGER.debug("Disconnected from bridge %s", self.host)
127+
await self._writer.wait_closed()
131128

132129
def is_connected(self) -> bool:
133130
"""Returns True if the bridge is connected."""
@@ -137,7 +134,7 @@ async def _send(self, request, request_type, params: dict = None, reply: bool =
137134
"""Sends a command and wait for a response if the request is known to return a result."""
138135
# Check if we are actually connected
139136
if not self.is_connected():
140-
raise AioComfoConnectNotConnected()
137+
raise AioComfoConnectNotConnected
141138

142139
# Construct the message
143140
cmd = zehnder_pb2.GatewayOperation() # pylint: disable=no-member
@@ -246,7 +243,8 @@ async def _process_message(self):
246243

247244
except asyncio.exceptions.IncompleteReadError:
248245
_LOGGER.info("The connection was closed.")
249-
raise AioComfoConnectNotConnected()
246+
await self._disconnect()
247+
raise AioComfoConnectNotConnected
250248

251249
except ComfoConnectError as exc:
252250
if exc.message.cmd.reference:

0 commit comments

Comments
 (0)