Raise HomeAssistantError from camera snapshot service (#137051)

* Raise HomeAssistantError from camera snapshot service

* Improve error message

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Nathan Spencer
2025-02-01 05:53:04 -07:00
committed by Paulus Schoutsen
parent 829a6271af
commit a4eab35e01
2 changed files with 27 additions and 13 deletions

View File

@@ -301,13 +301,24 @@ async def test_snapshot_service_not_allowed_path(hass: HomeAssistant) -> None:
@pytest.mark.usefixtures("mock_camera")
async def test_snapshot_service_os_error(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
@pytest.mark.parametrize(
("target", "side_effect"),
[
("homeassistant.components.camera.os.makedirs", OSError),
(
"homeassistant.components.demo.camera.DemoCamera.async_camera_image",
TimeoutError,
),
],
)
async def test_snapshot_service_error(
hass: HomeAssistant, target: str, side_effect: Exception
) -> None:
"""Test snapshot service with os error."""
"""Test snapshot service with error."""
with (
patch.object(hass.config, "is_allowed_path", return_value=True),
patch("homeassistant.components.camera.os.makedirs", side_effect=OSError),
patch(target, side_effect=side_effect),
pytest.raises(HomeAssistantError),
):
await hass.services.async_call(
camera.DOMAIN,
@@ -319,8 +330,6 @@ async def test_snapshot_service_os_error(
blocking=True,
)
assert "Can't write image to file:" in caplog.text
@pytest.mark.usefixtures("mock_camera", "mock_stream")
async def test_websocket_stream_no_source(