mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Skip firmware config flow confirmation if the hardware is in use (#142017)
* Auto-confirm the discovery if we detect that the device is already in use * Add a unit test
This commit is contained in:
parent
fc66997a36
commit
f29444002e
@ -33,6 +33,7 @@ from .util import (
|
||||
OwningIntegration,
|
||||
get_otbr_addon_manager,
|
||||
get_zigbee_flasher_addon_manager,
|
||||
guess_firmware_info,
|
||||
guess_hardware_owners,
|
||||
probe_silabs_firmware_info,
|
||||
)
|
||||
@ -511,6 +512,16 @@ class BaseFirmwareConfigFlow(BaseFirmwareInstallFlow, ConfigFlow):
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Confirm a discovery."""
|
||||
assert self._device is not None
|
||||
fw_info = await guess_firmware_info(self.hass, self._device)
|
||||
|
||||
# If our guess for the firmware type is actually running, we can save the user
|
||||
# an unnecessary confirmation and silently confirm the flow
|
||||
for owner in fw_info.owners:
|
||||
if await owner.is_running(self.hass):
|
||||
self._probed_firmware_info = fw_info
|
||||
return self._async_flow_finished()
|
||||
|
||||
return await self.async_step_pick_firmware()
|
||||
|
||||
|
||||
|
@ -381,6 +381,32 @@ async def test_config_flow_zigbee_skip_step_if_installed(hass: HomeAssistant) ->
|
||||
assert result["step_id"] == "confirm_zigbee"
|
||||
|
||||
|
||||
async def test_config_flow_auto_confirm_if_running(hass: HomeAssistant) -> None:
|
||||
"""Test the config flow skips the confirmation step the hardware is already used."""
|
||||
with patch(
|
||||
"homeassistant.components.homeassistant_hardware.firmware_config_flow.guess_firmware_info",
|
||||
return_value=FirmwareInfo(
|
||||
device=TEST_DEVICE,
|
||||
firmware_type=ApplicationType.EZSP,
|
||||
firmware_version="7.4.4.0",
|
||||
owners=[Mock(is_running=AsyncMock(return_value=True))],
|
||||
source="guess",
|
||||
),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
TEST_DOMAIN, context={"source": "hardware"}
|
||||
)
|
||||
|
||||
# There are no steps, the config entry is automatically created
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
config_entry = result["result"]
|
||||
assert config_entry.data == {
|
||||
"firmware": "ezsp",
|
||||
"device": TEST_DEVICE,
|
||||
"hardware": TEST_HARDWARE_NAME,
|
||||
}
|
||||
|
||||
|
||||
async def test_config_flow_thread(hass: HomeAssistant) -> None:
|
||||
"""Test the config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
Loading…
x
Reference in New Issue
Block a user