Skip to content

Commit a44d320

Browse files
committed
Catch all errors, close the websocket, then reraise the error
1 parent 25710e3 commit a44d320

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tibber/types/home.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ def start_live_feed(self, exit_condition: Callable[[LiveMeasurement], bool] = No
228228
if self.websocket_client:
229229
self.websocket_running = False
230230
self.tibber_client.eventloop.run_until_complete(self.websocket_client.close_async())
231+
except BaseException as e:
232+
# Close the websocket, then re-raise the exception
233+
if self.websocket_client:
234+
self.websocket_running = False
235+
self.tibber_client.eventloop.run_until_complete(self.websocket_client.close_async())
236+
raise e
237+
231238

232239
async def run_websocket_loop(self, exit_condition: Callable[[LiveMeasurement], bool] = None, retries: int = 3, retry_interval: Union[float, int] = 10, **kwargs) -> None:
233240
"""Starts a websocket to subscribe for live measurements.

0 commit comments

Comments
 (0)