1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-24 11:57:05 +00:00

Raise user-friendly error for locked ports when flashing ZBT (#157272)

This commit is contained in:
TheJulianJES
2025-11-26 04:37:09 +01:00
committed by GitHub
parent 9ebc6cbb23
commit 59f4bc1908
2 changed files with 22 additions and 3 deletions

View File

@@ -416,6 +416,10 @@ async def async_flash_silabs_firmware(
await flasher.flash_firmware(
fw_image, progress_callback=progress_callback
)
except PermissionError as err:
raise HomeAssistantError(
"Failed to flash firmware: Device is used by another application"
) from err
except Exception as err:
raise HomeAssistantError("Failed to flash firmware") from err

View File

@@ -666,7 +666,22 @@ async def test_async_flash_silabs_firmware_expected_type_not_probed(
)
async def test_async_flash_silabs_firmware_flash_failure(hass: HomeAssistant) -> None:
@pytest.mark.parametrize(
("side_effect", "expected_error_msg"),
[
(
RuntimeError("Failure!"),
"Failed to flash firmware",
),
(
PermissionError("The serial port is locked by another application"),
"Failed to flash firmware: Device is used by another application",
),
],
)
async def test_async_flash_silabs_firmware_flash_failure(
hass: HomeAssistant, side_effect: Exception, expected_error_msg: str
) -> None:
"""Test async_flash_silabs_firmware flash failure."""
await async_setup_component(hass, "homeassistant_hardware", {})
@@ -675,7 +690,7 @@ async def test_async_flash_silabs_firmware_flash_failure(hass: HomeAssistant) ->
mock_flasher = Mock()
mock_flasher.enter_bootloader = AsyncMock()
mock_flasher.flash_firmware = AsyncMock(side_effect=RuntimeError("Failure!"))
mock_flasher.flash_firmware = AsyncMock(side_effect=side_effect)
with (
patch(
@@ -695,7 +710,7 @@ async def test_async_flash_silabs_firmware_flash_failure(hass: HomeAssistant) ->
patch(
"homeassistant.components.homeassistant_hardware.util.parse_firmware_image"
),
pytest.raises(HomeAssistantError, match="Failed to flash firmware") as exc,
pytest.raises(HomeAssistantError, match=expected_error_msg) as exc,
):
await async_flash_silabs_firmware(
hass=hass,