From 7800a46f7b89847223b6859f7499e523c431fd03 Mon Sep 17 00:00:00 2001 From: Thomas <10558666+mosandlt@users.noreply.github.com> Date: Tue, 1 Dec 2026 14:52:15 +0100 Subject: [PATCH] Log the reason when the Bosch Smart Camera list request fails (#195784) Co-authored-by: Claude Sonnet 5.5 --- .../bosch_smart_camera/config_flow.py | 8 +++- .../bosch_smart_camera/test_config_flow.py | 40 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/bosch_smart_camera/config_flow.py b/homeassistant/components/bosch_smart_camera/config_flow.py index 3f5b71add6ef..fdd03ff9418d 100644 --- a/homeassistant/components/bosch_smart_camera/config_flow.py +++ b/homeassistant/components/bosch_smart_camera/config_flow.py @@ -85,7 +85,13 @@ class BoschCameraFlowHandler(AbstractOAuth2FlowHandler, domain=DOMAIN): await client.list_cameras() except BoschCameraAuthError: return self.async_abort(reason="invalid_auth") - except BoschCameraConnectionError, BoschCameraInvalidResponseError: + except (BoschCameraConnectionError, BoschCameraInvalidResponseError) as err: + self.logger.debug( + "Could not fetch the camera list: %s (HTTP status: %s, body: %s)", + err, + err.status, + err.body, + ) return self.async_abort(reason="cannot_connect") if self.source == SOURCE_REAUTH: return self.async_update_reload_and_abort( diff --git a/tests/components/bosch_smart_camera/test_config_flow.py b/tests/components/bosch_smart_camera/test_config_flow.py index c4ae800802eb..3b31e20838b2 100644 --- a/tests/components/bosch_smart_camera/test_config_flow.py +++ b/tests/components/bosch_smart_camera/test_config_flow.py @@ -3,6 +3,7 @@ import base64 from http import HTTPStatus import json +import logging from unittest.mock import AsyncMock from urllib.parse import parse_qs, urlparse @@ -286,3 +287,42 @@ async def test_reauth( assert result["reason"] == reason expected = new_token if reason == "reauth_successful" else "fake-access-token" assert mock_config_entry.data["token"]["access_token"] == expected + + +async def test_camera_list_failure_is_logged( + hass: HomeAssistant, + hass_client_no_auth: ClientSessionGenerator, + aioclient_mock: AiohttpClientMocker, + mock_list_cameras: AsyncMock, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test the reason of a failed camera list request is logged.""" + caplog.set_level(logging.DEBUG) + mock_list_cameras.side_effect = BoschCameraConnectionError( + "Camera list returned HTTP 503", status=503, body="maintenance" + ) + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_USER} + ) + state = config_entry_oauth2_flow._encode_jwt( + hass, {"flow_id": result["flow_id"], "redirect_uri": REDIRECT_URI} + ) + client = await hass_client_no_auth() + resp = await client.get(f"/auth/external/callback?code=abcd&state={state}") + assert resp.status == HTTPStatus.OK + + aioclient_mock.post( + OAUTH2_TOKEN, + json={ + "refresh_token": "mock-refresh-token", + "access_token": _fake_access_token({"sub": ACCOUNT_ID}), + "token_type": "Bearer", + "expires_in": 60, + }, + ) + result = await hass.config_entries.flow.async_configure(result["flow_id"]) + + assert result["reason"] == "cannot_connect" + assert "Camera list returned HTTP 503" in caplog.text + assert "HTTP status: 503" in caplog.text + assert "body: maintenance" in caplog.text