Files
vanlink/ha/custom_components/li3_battery/__init__.py
T
Andreas WredeandClaude Sonnet 5 d25f48727f ha: add li3_battery HA integration, replacing van-li3-battery
The li3 BMS has a persistently marginal BLE link from any single fixed
vantage point on this Pi (onboard adapter, a USB dongle that turned out to
be BR/EDR-only, and the Athom ESPHome BT proxy even after moving it closer).
Move capture into HA proper so bluetooth.async_ble_device_from_address can
pick whichever known source currently has the device, instead of hardcoding
one. Protocol parsing ported verbatim from li3/van-li3-battery.

van-li3-battery is disabled on the Pi; its MQTT discovery entities were
cleared.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 11:49:44 -04:00

28 lines
985 B
Python

"""The Lithionics Li3 BMS integration."""
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .const import DOMAIN
from .coordinator import Li3Coordinator
PLATFORMS: list[Platform] = [Platform.SENSOR]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
coordinator = Li3Coordinator(hass, entry.data["address"])
await coordinator.async_start()
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
coordinator: Li3Coordinator = hass.data[DOMAIN].pop(entry.entry_id)
await coordinator.async_stop()
return unload_ok