Fix BMS not responding to commands
- Use write_gatt_char with response=True (Write With Response) — many BMS firmwares ignore Write Without Response packets - Add 0.5s delay after start_notify before sending first command to avoid race where BMS hasn't registered the notification subscription yet Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,9 @@ class BmsBluetoothHandler:
|
||||
)
|
||||
await self._client.connect()
|
||||
await self._client.start_notify(RX_CHAR_UUID, self._on_notify)
|
||||
# Give the BMS a moment to register the notification subscription
|
||||
# before we start sending commands — avoids dropped first response
|
||||
await asyncio.sleep(0.5)
|
||||
_LOGGER.debug("Connected to BMS at %s", self._address)
|
||||
|
||||
async def disconnect(self) -> None:
|
||||
@@ -126,7 +129,7 @@ class BmsBluetoothHandler:
|
||||
self._response_event.clear()
|
||||
self._response_data = None
|
||||
try:
|
||||
await self._client.write_gatt_char(TX_CHAR_UUID, command, response=False)
|
||||
await self._client.write_gatt_char(TX_CHAR_UUID, command, response=True)
|
||||
except BleakError as exc:
|
||||
_LOGGER.error("BLE write failed: %s", exc)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user