mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 12:21:04 -04:00
Give SolarEdge Modbus reads a 30 s timeout (#185518)
This commit is contained in:
@@ -37,6 +37,7 @@ from .const import (
|
||||
DISCOVERY_SUBSYSTEMS,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
READ_TIMEOUT,
|
||||
SCAN_INTERVAL,
|
||||
SETTINGS_SCAN_INTERVAL,
|
||||
SUBSYSTEM_BATTERIES,
|
||||
@@ -106,6 +107,9 @@ async def async_setup_entry(
|
||||
translation_key="no_solaredge_device",
|
||||
) from err
|
||||
|
||||
# Only now: the probe gives up on a silent block after the link's default.
|
||||
unit.require_timeout(READ_TIMEOUT)
|
||||
|
||||
readings = SolarEdgeModbusDataUpdateCoordinator(
|
||||
hass,
|
||||
entry,
|
||||
|
||||
@@ -51,6 +51,12 @@ SUBSYSTEM_ADVANCED_POWER_CONTROL: Final = "advanced_power_control"
|
||||
SUBSYSTEM_POWER_CONTROL: Final = "power_control"
|
||||
SUBSYSTEM_SITE_CONTROL: Final = "site_control"
|
||||
|
||||
# How long a request may take once the inverter's blocks are known. Over Wi-Fi
|
||||
# a SolarEdge inverter answers some requests well past the link's default 10 s,
|
||||
# and one late answer fails the whole poll. Probing keeps the default: a block
|
||||
# the inverter never answers costs a full timeout there.
|
||||
READ_TIMEOUT: Final = 30
|
||||
|
||||
# Local Modbus is cheap to read and PV production moves fast.
|
||||
SCAN_INTERVAL: Final = timedelta(seconds=10)
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ from homeassistant.components.solaredge_modbus.const import (
|
||||
ATTACHMENT_SCAN_INTERVAL,
|
||||
CONF_SILENT_BLOCKS,
|
||||
DOMAIN,
|
||||
READ_TIMEOUT,
|
||||
SCAN_INTERVAL,
|
||||
SETTINGS_SCAN_INTERVAL,
|
||||
)
|
||||
@@ -1276,3 +1277,30 @@ async def test_only_a_block_a_check_reloads_for_is_kept(
|
||||
await _tick_attachment_check(hass, freezer)
|
||||
|
||||
assert mock_config_entry.data[CONF_SILENT_BLOCKS] == ["power_control"]
|
||||
|
||||
|
||||
async def test_reads_wait_longer_than_the_probe(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_modbus_unit: MockModbusUnit,
|
||||
) -> None:
|
||||
"""Polls get a longer timeout, the probe keeps the link's default.
|
||||
|
||||
Over Wi-Fi some answers come late, and one late answer fails a whole poll.
|
||||
The probe waits out a full timeout for every block the inverter never
|
||||
answers, so raising it there would only make setting up slower.
|
||||
"""
|
||||
during_probe: list[float | None] = []
|
||||
probe = SolarEdge.async_probe
|
||||
|
||||
async def recording_probe(
|
||||
unit: ModbusUnit, *, assume_absent: frozenset[str] = frozenset()
|
||||
) -> SolarEdge:
|
||||
during_probe.append(mock_modbus_unit.required_timeout)
|
||||
return await probe(unit, assume_absent=assume_absent)
|
||||
|
||||
with patch.object(SolarEdge, "async_probe", recording_probe):
|
||||
await _setup(hass, mock_config_entry)
|
||||
|
||||
assert during_probe == [None]
|
||||
assert mock_modbus_unit.required_timeout == READ_TIMEOUT
|
||||
|
||||
Reference in New Issue
Block a user