mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Log the reason when the Bosch Smart Camera list request fails (#195784)
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
3c4aab8940
commit
7800a46f7b
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user