From f890ebbf5445df09d1a0c93ff7fcfe4a315cc343 Mon Sep 17 00:00:00 2001 From: Markus Zehnder Date: Sun, 5 Nov 2023 16:58:34 +0100 Subject: [PATCH] fix: propagate SetupError in setup flow Propagate error_type if the integration driver returns a SetupError during the setup flow. --- ucapi/api.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ucapi/api.py b/ucapi/api.py index 1565bf3..cdac1b8 100644 --- a/ucapi/api.py +++ b/ucapi/api.py @@ -493,6 +493,7 @@ async def _setup_driver( await self.acknowledge_command(websocket, req_id) + result = False try: action = await self._setup_handler( uc.DriverSetupRequest(msg_data["setup_data"]) @@ -503,23 +504,26 @@ async def _setup_driver( await self.request_driver_setup_user_input( websocket, action.title, action.settings ) - return True + result = True if isinstance(action, uc.RequestUserConfirmation): await self.driver_setup_progress(websocket) await self.request_driver_setup_user_confirmation( websocket, action.title, action.header, action.image, action.footer ) - return True + result = True if isinstance(action, uc.SetupComplete): await self.driver_setup_complete(websocket) - return True + result = True + if isinstance(action, uc.SetupError): + await self.driver_setup_error(websocket, action.error_type) + result = True # error action is left, handled below # TODO define custom exceptions? except Exception as ex: # pylint: disable=W0718 _LOG.error("Exception in setup handler, aborting setup! Exception: %s", ex) - return False + return result async def _set_driver_user_data( self, websocket, req_id: int, msg_data: dict[str, Any] | None