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

Multiple active connections due to incorrect Bluetooth handling #71

Closed patman15 closed 3 weeks ago

patman15 commented 3 weeks ago

Checklist

Describe the issue

There are two possibilities on how multiple connection can happen: a. failure on initial update results in retry which generates a new connection b. race condition when connection is interrupted (timeout for detecting) and a retry is triggered

Relevant observations: #58 #35

Reproduction steps

For (a) only:

  1. Let the initial connection setup fail multiple times, e.g. move it out of range
  2. Let the connection being established, e.g. move into range
  3. observe redundant data detected

Debug logs

2024-10-30 18:50:51.091 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) cmd=10 size=1 sign=False
2024-10-30 18:50:51.091 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) {11: bytearray(b'\xaaU\x0b\x08X4\x00\x00\x00\x00\x00\x00\x9f\r\n'), 9: bytearray(b'\xaaU\t\x0c\x15\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00?\r\n'), 10: bytearray(b'\xaaU\n\x06d\x13\r\x00\x00\x00\x94\r\n')}
2024-10-30 18:50:51.091 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) request design_capacity info
2024-10-30 18:50:51.287 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) Rx BLE data: bytearray(b'\xaaU\x15\x04(\x00\x03\x00D\r\n')
2024-10-30 18:50:51.287 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) Rx BLE data: bytearray(b'\xaaU\x15\x04(\x00\x03\x00D\r\n')
2024-10-30 18:50:51.287 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) Rx BLE data: bytearray(b'\xaaU\x15\x04(\x00\x03\x00D\r\n')
2024-10-30 18:50:51.287 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) Rx BLE data: bytearray(b'\xaaU\x15\x04(\x00\x03\x00D\r\n')
2024-10-30 18:50:51.288 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) Rx BLE data: bytearray(b'\xaaU\x15\x04(\x00\x03\x00D\r\n')
2024-10-30 18:50:51.288 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) Rx BLE data: bytearray(b'\xaaU\x15\x04(\x00\x03\x00D\r\n')
2024-10-30 18:50:51.288 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) Rx BLE data: bytearray(b'\xaaU\x15\x04(\x00\x03\x00D\r\n')
2024-10-30 18:50:51.288 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) Rx BLE data: bytearray(b'\xaaU\x15\x04(\x00\x03\x00D\r\n')
2024-10-30 18:50:51.288 DEBUG (MainThread) [custom_components.bms_ble.plugins.cbtpwr_bms] (140R00036D) Rx BLE data: bytearray(b'\xaaU\x15\x04(\x00\x03\x00D\r\n')