1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-13 01:27:57 +01:00

Unload platforms in stiebel_eltron before closing connection in async_unload_entry (#175776)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Manuel Stahl
2026-07-06 17:41:15 +02:00
committed by GitHub
parent 3261a1fbfb
commit 680f414f76
3 changed files with 44 additions and 5 deletions
@@ -45,6 +45,6 @@ async def async_unload_entry(
entry: StiebelEltronConfigEntry,
) -> bool:
"""Unload a config entry."""
coordinator = entry.runtime_data
await coordinator.close()
return await hass.config_entries.async_unload_platforms(entry, _PLATFORMS)
if unload_ok := await hass.config_entries.async_unload_platforms(entry, _PLATFORMS):
await entry.runtime_data.close()
return unload_ok
@@ -31,7 +31,7 @@ rules:
# Silver
action-exceptions: todo
config-entry-unloading: todo
config-entry-unloading: done
docs-configuration-parameters:
status: exempt
comment: Integration does not have an options flow.
+40 -1
View File
@@ -1,6 +1,6 @@
"""Tests for the STIEBEL ELTRON integration."""
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch
from pymodbus.exceptions import ModbusException
from pystiebeleltron import StiebelEltronModbusError
@@ -89,3 +89,42 @@ async def test_async_setup_entry_coordinator_update_fails(
assert result is False
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_unload_entry_closes_connection(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_lwz_api: MagicMock,
) -> None:
"""Test unloading the config entry closes the Modbus connection."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.async_unload(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert result is True
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
mock_lwz_api.close.assert_awaited_once()
async def test_unload_entry_does_not_close_connection_if_platform_unload_fails(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_lwz_api: MagicMock,
) -> None:
"""Test the connection is not closed if platform unload fails."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
with patch(
"homeassistant.config_entries.ConfigEntries.async_unload_platforms",
return_value=False,
):
result = await hass.config_entries.async_unload(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert result is False
mock_lwz_api.close.assert_not_awaited()