aiocomfoconnect 0.4.0__tar.gz → 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aiocomfoconnect
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: aiocomfoconnect is an asyncio Python 3 library for communicating with a Zehnder ComfoAir Q350/450/600 ventilation system
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -280,6 +280,21 @@ class ComfoConnect(Bridge):
280
280
  raise AioComfoConnectNotConnected("Not connected to bridge")
281
281
  return super().cmd_rmi_request(message, node_id)
282
282
 
283
+ async def _send(self, request, request_type, params: dict = None, reply: bool = True, timeout: float = None) -> Message:
284
+ """Send a request, and close the connection when the bridge dropped our session.
285
+
286
+ The bridge can drop our session without closing the connection, e.g. when another app takes over a session with our
287
+ uuid. It then answers every request with NOT_ALLOWED (or OTHER_SESSION). Closing the connection lets the reconnect
288
+ loop start a new session. The request still raises its error.
289
+ """
290
+ try:
291
+ return await super()._send(request, request_type, params, reply, timeout)
292
+ except (ComfoConnectNotAllowed, ComfoConnectOtherSession):
293
+ if self._connection_state == ConnectionState.CONNECTED and self._writer is not None:
294
+ _LOGGER.warning("The bridge dropped our session, reconnecting")
295
+ self._writer.close()
296
+ raise
297
+
283
298
  async def disconnect(self):
284
299
  """Disconnect from the bridge and stop reconnecting. A connect() that is still busy fails."""
285
300
  _LOGGER.debug("Stopping reconnection and disconnecting")
@@ -2,6 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from .protobuf import zehnder_pb2
6
+
5
7
 
6
8
  class AioComfoConnectError(Exception):
7
9
  """Base class for all errors raised by aiocomfoconnect."""
@@ -12,7 +14,13 @@ class ComfoConnectError(AioComfoConnectError):
12
14
 
13
15
  def __init__(self, message):
14
16
  cmd = getattr(message, "cmd", None)
15
- super().__init__((cmd.resultDescription or f"reference {cmd.reference}") if cmd else str(message))
17
+ if cmd is None:
18
+ text = str(message)
19
+ else:
20
+ result = zehnder_pb2.GatewayOperation.GatewayResult.Name(cmd.result) # pylint: disable=no-member
21
+ description = f": {cmd.resultDescription}" if cmd.resultDescription else ""
22
+ text = f"{result}{description} (reference {cmd.reference})"
23
+ super().__init__(text)
16
24
  self.message = message
17
25
 
18
26
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "aiocomfoconnect"
3
- version = "0.4.0"
3
+ version = "0.4.1"
4
4
  description = "aiocomfoconnect is an asyncio Python 3 library for communicating with a Zehnder ComfoAir Q350/450/600 ventilation system"
5
5
  authors = ["Michaël Arnauts <michael.arnauts@gmail.com>"]
6
6
  license = "MIT"
File without changes