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
34 stars 8 forks source link

JK/JBD BMS sometimes reports 0 values #51

Closed patman15 closed 1 month ago

patman15 commented 1 month ago

Checklist

Describe the issue

v1.6.2 works while v1.6.3 sometimes produces 0 values as it can be seen here: image

Issue is caused by clearing bytearray which is later assigned (not copied) to final version: https://github.com/patman15/BMS_BLE-HA/commit/8e9c1b7c934d6837fb3f93f2032b290c7677ed2d#diff-ce80ef634830b4483558d11765fb3faca12bf0ee435cd5f85faa072835be557dR106

Reproduction steps

  1. run integration v1.6.2 using JK BMS
  2. wait some time, as it is a timing related issue

Debug logs

2024-09-21 17:06:29.600 DEBUG (MainThread) [custom_components.bms_ble.plugins.jikong_bms] BMS BatteryOben-00 already connected
2024-09-21 17:06:29.600 DEBUG (MainThread) [custom_components.bms_ble.plugins.jikong_bms] (BatteryOben-00) Wrong data length (150): bytearray(b'U\xaa\xeb\x90\x02#\x85\r\x83\r\x83\r\x83\r\x83\r\x83\r\x83\r\x83\r\x83\r\x83\r\x83\r\x83\r\x83\r\x85\r\x85\r\x85\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x84\r\x03\x00\t\x00:\x00<\x00F\x00H\x00T\x00\\\x00i\x00v\x00}\x00v\x00l\x00i\x00a\x00K\x00G\x00<\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf7\x00\x00\x00\x00\x00')
2024-09-21 17:06:29.600 DEBUG (MainThread) [custom_components.bms_ble] BMS data sample {'cell_count': 16, 'delta_voltage': 0.003, 'temp#0': 24.7, 'temp#1': 0.0, 'temp#2': 0.0, 'voltage': 0.0, 'current': 0.0, 'battery_level': 0, 'cycle_charge': 0.0, 'cycles': 0, 'cell#0': 3.461, 'cell#1': 3.459, 'cell#2': 3.459, 'cell#3': 3.459, 'cell#4': 3.459, 'cell#5': 3.459, 'cell#6': 3.459, 'cell#7': 3.459, 'cell#8': 3.459, 'cell#9': 3.459, 'cell#10': 3.459, 'cell#11': 3.459, 'cell#12': 3.459, 'cell#13': 3.461, 'cell#14': 3.461, 'cell#15': 3.461, 'cycle_capacity': 0.0, 'power': 0.0, 'battery_charging': False, 'temperature': 8.233, 'rssi': -74}
patman15 commented 1 month ago

Code review showed similar issue for JBD