From 58c2c16486ae1e55928bdebbf5bc5293d68f73b9 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Tue, 14 Sep 2021 08:42:00 +1200 Subject: [PATCH] Only route messages if connection is not None We have an edge case when using a ChargePoint instance with Home Assistant (https://github.com/lbbrhzn/ocpp/) where the Charger does not close its websocket properly and keeps sending messages. In the integration we want to keep the ChargePoint instance and simply reconnect the websocket when it fails eg network, reboot etc. This can be done by setting the `_connection` to `None` but with the current code `while True` throws an `AttributeError`. Checking the connection is not none would solve this and is preferable to checking the websocket is still open in my view. --- ocpp/charge_point.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocpp/charge_point.py b/ocpp/charge_point.py index 5b50a18a6..cb07c77f0 100644 --- a/ocpp/charge_point.py +++ b/ocpp/charge_point.py @@ -119,7 +119,7 @@ def __init__(self, id, connection, response_timeout=30): self._unique_id_generator = uuid.uuid4 async def start(self): - while True: + while self._connection is not None: message = await self._connection.recv() LOGGER.info('%s: receive message %s', self.id, message)