Add MOS gate control via select entity
Adds a Select entity with four options (Normal / Charge Disabled / Discharge Disabled / Both Disabled) that sends the 0xE1 write command to the BMS and immediately refreshes sensor state. Current option is derived from the mos_charge_enabled / mos_discharge_enabled bits already parsed on every poll. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ from datetime import timedelta
|
||||
|
||||
from homeassistant.components.bluetooth import async_ble_device_from_address
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
@@ -71,6 +72,19 @@ class BmsCoordinator(DataUpdateCoordinator[dict]):
|
||||
async def async_teardown(self) -> None:
|
||||
"""No-op — each poll disconnects itself."""
|
||||
|
||||
async def async_write_mos(self, value: int) -> None:
|
||||
"""Send a MOS control command to the BMS, then refresh sensor state."""
|
||||
device = async_ble_device_from_address(self.hass, self.address, connectable=True)
|
||||
if device is None:
|
||||
raise HomeAssistantError(
|
||||
f"BMS ({self.address}) not reachable — cannot send MOS command"
|
||||
)
|
||||
success = await self._handler.write_mos(device, value)
|
||||
if not success:
|
||||
raise HomeAssistantError("BMS did not acknowledge the MOS command")
|
||||
# Refresh immediately so sensors reflect the new MOS state
|
||||
await self.async_request_refresh()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Poll
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user