Jc2k/aiohomekit

Handle timeout during setup

bdraco opened this issue · 2 comments

Logger: homeassistant.config_entries
Source: components/esphome/bluetooth/client.py:66
First occurred: 12:21:49 PM (1 occurrences)
Last logged: 12:21:49 PM

Error setting up entry for homekit_controller
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 460, in send_message_await_response_complex
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 459, in send_message_await_response_complex
    async with async_timeout.timeout(timeout):
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/homeassistant/components/esphome/bluetooth/client.py", line 64, in _async_wrap_bluetooth_operation
    return await func(self, *args, **kwargs)
  File "/Users/bdraco/home-assistant/homeassistant/components/esphome/bluetooth/client.py", line 323, in read_gatt_char
    return await self._client.bluetooth_gatt_read(
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aioesphomeapi/client.py", line 538, in bluetooth_gatt_read
    resp = await self._connection.send_message_await_response_complex(
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 462, in send_message_await_response_complex
    raise TimeoutAPIError(
aioesphomeapi.core.TimeoutAPIError: Timeout waiting for response for <class 'api_pb2.BluetoothGATTReadRequest'>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 365, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/Users/bdraco/home-assistant/homeassistant/components/homekit_controller/__init__.py", line 42, in async_setup_entry
    await conn.async_setup()
  File "/Users/bdraco/home-assistant/homeassistant/components/homekit_controller/connection.py", line 198, in async_setup
    await self.pairing.async_populate_accessories_state(force_update=True)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 534, in async_populate_accessories_state
    await self._async_populate_accessories_state(force_update)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 110, in _async_wrap
    return await func(self, *args, **kwargs)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/client.py", line 76, in _async_wrap
    return await func(*args, **kwargs)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 546, in _async_populate_accessories_state
    await self._populate_accessories_and_characteristics(force_update)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 580, in _populate_accessories_and_characteristics
    await self._populate_char_values(config_changed)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 513, in _populate_char_values
    results = await self._get_characteristics_while_connected(chars)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 717, in _get_characteristics_while_connected
    data = await self._async_request_under_lock(OpCode.CHAR_READ, char)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 250, in _async_request_under_lock
    pdu_status, result_data = await ble_request(
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/client.py", line 101, in ble_request
    return await _read_pdu(client, decryption_key, handle, tid)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohomekit/controller/ble/client.py", line 137, in _read_pdu
    data = await client.read_gatt_char(handle)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/bleak/__init__.py", line 482, in read_gatt_char
    return await self._backend.read_gatt_char(char_specifier, **kwargs)
  File "/Users/bdraco/home-assistant/homeassistant/components/esphome/bluetooth/client.py", line 52, in _async_wrap_bluetooth_connected_operation
    return await func(self, *args, **kwargs)
  File "/Users/bdraco/home-assistant/homeassistant/components/esphome/bluetooth/client.py", line 66, in _async_wrap_bluetooth_operation
    raise asyncio.TimeoutError(str(err)) from err
asyncio.exceptions.TimeoutError: Timeout waiting for response for <class 'api_pb2.BluetoothGATTReadRequest'>

I think we should handle this in HASS instead