patman15 / BMS_BLE-HA

This integration allows to monitor Bluetooth Low Energy (BLE) battery management systems (BMS) from within Home Assistant.
GNU Lesser General Public License v2.1
50 stars 9 forks source link

Unexpected error fetching BMS data #67

Closed patman15 closed 1 month ago

patman15 commented 1 month ago

Checklist

Describe the issue

In rare cases the bluetooth connection can fail with EOFError instead of a BleakError, e.g. see https://github.com/hbldh/bleak/issues/409

Reproduction steps

  1. run multiple BMS devices in parallel
  2. wait for a while (happens rarely)

Debug logs

2024-10-26 12:58:46.983 ERROR (MainThread) [custom_components.bms_ble] Unexpected error fetching JK-BD6A24S10P data
Traceback (most recent call last):
  File "/srv/HAcore/homeassistant/helpers/update_coordinator.py", line 382, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/HAcore/config2/custom_components/bms_ble/coordinator.py", line 94, in _async_update_data
    battery_info = await self._device.async_update()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/HAcore/config2/custom_components/bms_ble/plugins/jikong_bms.py", line 248, in async_update
    await self._client.write_gatt_char(
  File "/srv/HAcore/venv/lib/python3.12/site-packages/bleak/__init__.py", line 786, in write_gatt_char
    await self._backend.write_gatt_char(characteristic, data, response)
  File "/srv/HAcore/venv/lib/python3.12/site-packages/bleak/backends/bluezdbus/client.py", line 835, in write_gatt_char
    reply = await self._bus.call(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/srv/HAcore/venv/lib/python3.12/site-packages/dbus_fast/aio/message_bus.py", line 385, in call
    await future
  File "src/dbus_fast/aio/message_reader.py", line 19, in dbus_fast.aio.message_reader._message_reader
  File "src/dbus_fast/_private/unmarshaller.py", line 775, in dbus_fast._private.unmarshaller.Unmarshaller._unmarshall
  File "src/dbus_fast/_private/unmarshaller.py", line 636, in dbus_fast._private.unmarshaller.Unmarshaller._read_header
  File "src/dbus_fast/_private/unmarshaller.py", line 374, in dbus_fast._private.unmarshaller.Unmarshaller._read_to_pos
  File "src/dbus_fast/_private/unmarshaller.py", line 317, in dbus_fast._private.unmarshaller.Unmarshaller._read_sock_with_fds
EOFError