From 38531033a184994ef4b5be0f1bfb580a59a0e38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=96dlund?= Date: Thu, 12 Feb 2026 11:51:09 -0800 Subject: [PATCH] Catch AccessoryDisconnectedError in homekit pairing (#162466) Co-authored-by: Claude Opus 4.6 --- .../components/homekit_controller/config_flow.py | 12 ++++++++++++ .../components/homekit_controller/strings.json | 1 + .../homekit_controller/test_config_flow.py | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/homekit_controller/config_flow.py b/homeassistant/components/homekit_controller/config_flow.py index df6d4498f9c..3b15e69b149 100644 --- a/homeassistant/components/homekit_controller/config_flow.py +++ b/homeassistant/components/homekit_controller/config_flow.py @@ -460,6 +460,12 @@ class HomekitControllerFlowHandler(ConfigFlow, domain=DOMAIN): except aiohomekit.AccessoryNotFoundError: # Can no longer find the device on the network return self.async_abort(reason="accessory_not_found_error") + except aiohomekit.AccessoryDisconnectedError as err: + # The accessory has disconnected from the network + return self.async_abort( + reason="accessory_disconnected_error", + description_placeholders={"error": str(err)}, + ) except InsecureSetupCode: errors["pairing_code"] = "insecure_setup_code" except Exception as err: @@ -490,6 +496,12 @@ class HomekitControllerFlowHandler(ConfigFlow, domain=DOMAIN): except aiohomekit.AccessoryNotFoundError: # Can no longer find the device on the network return self.async_abort(reason="accessory_not_found_error") + except aiohomekit.AccessoryDisconnectedError as err: + # The accessory has disconnected from the network + return self.async_abort( + reason="accessory_disconnected_error", + description_placeholders={"error": str(err)}, + ) except IndexError: # TLV error, usually not in pairing mode _LOGGER.exception("Pairing communication failed") diff --git a/homeassistant/components/homekit_controller/strings.json b/homeassistant/components/homekit_controller/strings.json index a87df5d4515..68eafb941a9 100644 --- a/homeassistant/components/homekit_controller/strings.json +++ b/homeassistant/components/homekit_controller/strings.json @@ -1,6 +1,7 @@ { "config": { "abort": { + "accessory_disconnected_error": "A connectivity error occurred while attempting to pair with this device.\n\n{error}", "accessory_not_found_error": "Cannot add pairing as device can no longer be found.", "already_configured": "Accessory is already configured with this controller.", "already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]", diff --git a/tests/components/homekit_controller/test_config_flow.py b/tests/components/homekit_controller/test_config_flow.py index ce6b4066e8f..ddce7654934 100644 --- a/tests/components/homekit_controller/test_config_flow.py +++ b/tests/components/homekit_controller/test_config_flow.py @@ -34,6 +34,7 @@ PAIRING_START_FORM_ERRORS = [ ] PAIRING_START_ABORT_ERRORS = [ + (aiohomekit.AccessoryDisconnectedError, "accessory_disconnected_error"), (aiohomekit.AccessoryNotFoundError, "accessory_not_found_error"), (aiohomekit.UnavailableError, "already_paired"), ] @@ -53,7 +54,8 @@ PAIRING_FINISH_FORM_ERRORS = [ ] PAIRING_FINISH_ABORT_ERRORS = [ - (aiohomekit.AccessoryNotFoundError, "accessory_not_found_error") + (aiohomekit.AccessoryDisconnectedError, "accessory_disconnected_error"), + (aiohomekit.AccessoryNotFoundError, "accessory_not_found_error"), ]