mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Keep Sofar meter sensors while the inverter type is unsettled (#186496)
This commit is contained in:
@@ -177,9 +177,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: SofarConfigEntry) -> Non
|
||||
config_entry_id=entry.entry_id, **readings.device_info
|
||||
)
|
||||
entry.runtime_data = SofarRuntimeData(readings, settings, inverter.id)
|
||||
_async_remove_denied_meter_energy(
|
||||
hass, serial, entry.runtime_data.served_components
|
||||
)
|
||||
# Until the masks settle the type, nothing is served or denied.
|
||||
if device.inverter_type:
|
||||
_async_remove_denied_meter_energy(
|
||||
hass, serial, entry.runtime_data.served_components
|
||||
)
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
|
||||
@@ -464,6 +464,37 @@ async def test_setup_takes_the_type_once_the_masks_answer(
|
||||
assert len(hass.states.async_all()) == 37
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_get_unit")
|
||||
async def test_setup_while_asleep_keeps_meter_sensors_of_an_unsettled_type(
|
||||
hass: HomeAssistant,
|
||||
mock_connection: MockModbusConnection,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test a silent restart keeps meter sensors before the masks answer."""
|
||||
entry = _unrecognized_entry(mock_connection)
|
||||
unit = mock_connection.for_unit(1)
|
||||
declare_pv_in_masks(unit)
|
||||
unit.fail_requests(ModbusTimeoutError("asleep"))
|
||||
entry.add_to_hass(hass)
|
||||
meter_sensors = [
|
||||
entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"{MOCK_UNRECOGNIZED_SERIAL}_{key}",
|
||||
config_entry=entry,
|
||||
).entity_id
|
||||
for key in METER_ENERGY_KEYS
|
||||
]
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
assert all(
|
||||
entity_registry.async_get(entity_id) is not None for entity_id in meter_sensors
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_get_unit")
|
||||
async def test_setup_while_asleep_keeps_the_device_versions(
|
||||
hass: HomeAssistant,
|
||||
|
||||
Reference in New Issue
Block a user