diff --git a/homeassistant/components/homekit_controller/connection.py b/homeassistant/components/homekit_controller/connection.py index 4d8d26fb557..320df671144 100644 --- a/homeassistant/components/homekit_controller/connection.py +++ b/homeassistant/components/homekit_controller/connection.py @@ -35,6 +35,7 @@ from .const import ( IDENTIFIER_LEGACY_ACCESSORY_ID, IDENTIFIER_LEGACY_SERIAL_NUMBER, IDENTIFIER_SERIAL_NUMBER, + STARTUP_EXCEPTIONS, ) from .device_trigger import async_fire_triggers, async_setup_triggers_for_entry @@ -187,11 +188,12 @@ class HKDevice: """ try: await self.pairing.async_populate_accessories_state(force_update=True) - except (asyncio.TimeoutError, AccessoryNotFoundError): + except STARTUP_EXCEPTIONS as ex: _LOGGER.debug( "Failed to populate BLE accessory state for %s, accessory may be sleeping" - " and will be retried the next time it advertises", + " and will be retried the next time it advertises: %s", self.config_entry.title, + ex, ) async def async_setup(self) -> None: @@ -220,7 +222,7 @@ class HKDevice: # BLE devices may sleep and we can't force a connection raise entry.async_on_unload( - self.hass.bus.async_listen_once( + self.hass.bus.async_listen( EVENT_HOMEASSISTANT_STARTED, self._async_retry_populate_ble_accessory_state, ) diff --git a/homeassistant/components/homekit_controller/const.py b/homeassistant/components/homekit_controller/const.py index 5ea8205260e..8c7db4dad00 100644 --- a/homeassistant/components/homekit_controller/const.py +++ b/homeassistant/components/homekit_controller/const.py @@ -1,6 +1,12 @@ """Constants for the homekit_controller component.""" +import asyncio from typing import Final +from aiohomekit.exceptions import ( + AccessoryDisconnectedError, + AccessoryNotFoundError, + EncryptionError, +) from aiohomekit.model.characteristics import CharacteristicsTypes from aiohomekit.model.services import ServicesTypes @@ -94,3 +100,10 @@ CHARACTERISTIC_PLATFORMS = { # Device classes DEVICE_CLASS_ECOBEE_MODE: Final = "homekit_controller__ecobee_mode" + +STARTUP_EXCEPTIONS = ( + asyncio.TimeoutError, + AccessoryNotFoundError, + EncryptionError, + AccessoryDisconnectedError, +)