Settle SolarEdge Modbus battery probes when storage control is silent (#191778)

This commit is contained in:
tronikos
2026-11-25 16:19:06 -08:00
committed by GitHub
parent c61bb9579b
commit 249adbcf4b
2 changed files with 55 additions and 5 deletions
@@ -208,13 +208,26 @@ async def async_setup_entry(
)
def _settleable_blocks(blocks: AbstractSet[str]) -> frozenset[str]:
"""Return the silent blocks from `blocks` that can be settled as absent.
Blocks that finding hardware depends on are never settled on their own,
except batteries when storage control is also silent (meaning the inverter
does not serve the 57xxx StorEdge register space at all).
"""
settled = frozenset(blocks) - DISCOVERY_SUBSYSTEMS
if SUBSYSTEM_STORAGE_CONTROL in settled and SUBSYSTEM_BATTERIES in blocks:
return settled | {SUBSYSTEM_BATTERIES}
return settled
def _known_silent_blocks(entry: SolarEdgeModbusConfigEntry) -> frozenset[str]:
"""Return the blocks the last attachment check settled as silent.
Blocks that finding hardware depends on are never settled, so one stored
by anything else is not taken for absent either.
Blocks that finding hardware depends on are never settled on their own, so
one stored by anything else is not taken for absent either.
"""
return frozenset(entry.data.get(CONF_SILENT_BLOCKS, ())) - DISCOVERY_SUBSYSTEMS
return _settleable_blocks(frozenset(entry.data.get(CONF_SILENT_BLOCKS, ())))
def _attachment_identities(solaredge: SolarEdge) -> frozenset[str]:
@@ -285,9 +298,9 @@ async def _async_reload_when_attachments_change(
# later removal until the entry loads again. Blocks that finding hardware
# depends on are never settled: picking up what was wired in later is what
# asking is for.
settled = (
settled = _settleable_blocks(
probed.unresponsive_blocks & solaredge.unresponsive_blocks
) - DISCOVERY_SUBSYSTEMS
)
entry.runtime_data.settled_silent_blocks = settled
# Kept with the entry for the next setup, before a reload below can start
@@ -1354,3 +1354,40 @@ async def test_attachment_check_skipped_when_polling_disabled(
await _tick_attachment_check(hass, freezer)
mock_probe.assert_not_called()
async def test_batteries_settled_when_storage_control_is_silent(
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
mock_config_entry: MockConfigEntry,
mock_modbus_unit: MockModbusUnit,
) -> None:
"""Batteries are settled alongside storage control when both stay silent."""
mock_modbus_unit.fail_read(SITE_CONTROL_REGISTER, ModbusTimeoutError("timed out"))
mock_modbus_unit.fail_read(BATTERY_RATED_ENERGY, ModbusTimeoutError("timed out"))
await _setup(hass, mock_config_entry)
asked: list[frozenset[str]] = []
probe = SolarEdge.async_probe
async def recording_probe(
unit: ModbusUnit, *, assume_absent: frozenset[str] = frozenset()
) -> SolarEdge:
asked.append(assume_absent)
return await probe(unit, assume_absent=assume_absent)
with patch.object(SolarEdge, "async_probe", recording_probe):
await _tick_attachment_check(hass, freezer)
await _tick_attachment_check(hass, freezer)
await hass.config_entries.async_reload(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert asked == [
frozenset(),
frozenset({"batteries", "storage_control"}),
frozenset({"batteries", "storage_control"}),
]
assert mock_config_entry.data[CONF_SILENT_BLOCKS] == [
"batteries",
"storage_control",
]