Use BLE device name, add hard poll timeout, tighten request timing

- Device name: coordinator now takes name=entry.title so the HA device card
  shows the actual BLE advertised name instead of "Xiaoxiang Smart BMS"
- Hard poll timeout: each poll is capped at (poll_interval - 3)s via
  asyncio.wait_for so a stalled poll can't bleed into the next cycle
- Request timeout: 5s → 3s (BMS should reply in <1s under normal conditions)
- Retry delay: 0.5s → 0.3s between retries

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 20:21:37 +02:00
parent 3fc25c083b
commit e1e6d69d2c
3 changed files with 18 additions and 7 deletions
+13 -2
View File
@@ -1,6 +1,7 @@
"""DataUpdateCoordinator for the Xiaoxiang Smart BMS."""
from __future__ import annotations
import asyncio
import logging
from datetime import timedelta
@@ -27,6 +28,7 @@ class BmsCoordinator(DataUpdateCoordinator[dict]):
hass: HomeAssistant,
address: str,
poll_interval: int,
name: str = "Xiaoxiang Smart BMS",
) -> None:
super().__init__(
hass,
@@ -35,6 +37,8 @@ class BmsCoordinator(DataUpdateCoordinator[dict]):
update_interval=timedelta(seconds=poll_interval),
)
self.address = address
self._device_name = name
self._poll_timeout = max(poll_interval - 3, 10) # hard cap, leaves 3s slack
self._handler = BmsBluetoothHandler(address)
self.hw_version: str | None = None
@@ -46,7 +50,7 @@ class BmsCoordinator(DataUpdateCoordinator[dict]):
def device_info(self) -> DeviceInfo:
return DeviceInfo(
identifiers={(DOMAIN, self.address)},
name="Xiaoxiang Smart BMS",
name=self._device_name,
manufacturer="Xiaoxiang",
model=self.hw_version or "Smart BMS",
)
@@ -79,7 +83,14 @@ class BmsCoordinator(DataUpdateCoordinator[dict]):
commands.append(CMD_VERSION)
try:
responses = await self._handler.poll(device, commands)
responses = await asyncio.wait_for(
self._handler.poll(device, commands),
timeout=self._poll_timeout,
)
except asyncio.TimeoutError:
raise UpdateFailed(
f"BMS poll timed out after {self._poll_timeout}s"
)
except Exception as exc:
raise UpdateFailed(f"BMS poll failed: {exc}") from exc