Support ESPHome BLE proxies via HA Bluetooth subsystem

Use async_ble_device_from_address() to resolve the BMS through whichever
adapter (local or ESPHome proxy) can reach it, instead of connecting by
raw MAC address directly. BleakClient now receives a BLEDevice object.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-11 19:33:04 +02:00
parent ea1e74c384
commit db45679c12
2 changed files with 27 additions and 6 deletions
@@ -6,6 +6,7 @@ import logging
import struct
from bleak import BleakClient, BleakError
from bleak.backends.device import BLEDevice
from .const import (
FRAME_END,
@@ -42,13 +43,17 @@ class BmsBluetoothHandler:
def is_connected(self) -> bool:
return self._client is not None and self._client.is_connected
async def connect(self) -> None:
"""Open BLE connection and start notifications."""
async def connect(self, ble_device: BLEDevice) -> None:
"""Open BLE connection and start notifications.
Accepts a BLEDevice resolved by HA's Bluetooth subsystem so that
ESPHome BLE proxies are used transparently alongside local adapters.
"""
if self.is_connected:
return
_LOGGER.debug("Connecting to BMS at %s", self._address)
_LOGGER.debug("Connecting to BMS at %s (via %s)", self._address, ble_device.name)
self._client = BleakClient(
self._address,
ble_device,
disconnected_callback=self._on_disconnect,
)
await self._client.connect()