Unload ZHA integration before adapter migration (#152896)

This commit is contained in:
puddly
2025-09-24 17:28:55 +02:00
committed by GitHub
parent dfbaf66021
commit 70077511a3
2 changed files with 22 additions and 4 deletions
@@ -444,6 +444,10 @@ class BaseZhaFlow(ConfigEntryBaseFlow):
assert len(config_entries) == 1
config_entry = config_entries[0]
# Unload ZHA before connecting to the old adapter
with suppress(OperationNotAllowed):
await self.hass.config_entries.async_unload(config_entry.entry_id)
# Create a radio manager to connect to the old stick to reset it
temp_radio_mgr = ZhaRadioManager()
temp_radio_mgr.hass = self.hass
+18 -4
View File
@@ -5,7 +5,14 @@ from datetime import timedelta
from ipaddress import ip_address
import json
from typing import Any
from unittest.mock import AsyncMock, MagicMock, PropertyMock, create_autospec, patch
from unittest.mock import (
AsyncMock,
MagicMock,
PropertyMock,
call,
create_autospec,
patch,
)
import uuid
import pytest
@@ -585,14 +592,21 @@ async def test_migration_strategy_recommended(
assert result_confirm["step_id"] == "choose_migration_strategy"
with patch(
"homeassistant.components.zha.radio_manager.ZhaRadioManager.restore_backup",
) as mock_restore_backup:
with (
patch(
"homeassistant.components.zha.radio_manager.ZhaRadioManager.restore_backup",
) as mock_restore_backup,
patch(
"homeassistant.config_entries.ConfigEntries.async_unload",
return_value=True,
) as mock_async_unload,
):
result_recommended = await hass.config_entries.flow.async_configure(
result_confirm["flow_id"],
user_input={"next_step_id": config_flow.MIGRATION_STRATEGY_RECOMMENDED},
)
assert mock_async_unload.mock_calls == [call(entry.entry_id)]
assert result_recommended["type"] is FlowResultType.ABORT
assert result_recommended["reason"] == "reconfigure_successful"
mock_restore_backup.assert_called_once()