Decrease fitbit logging verbosity on connection error (#108228)

* Add test for connection error

* Decrease fitbit connection error log verbosity
pull/108248/head
Martin Hjelmare 2024-01-17 16:07:02 +01:00 committed by GitHub
parent c47fb5d161
commit 9d5f714e29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -7,6 +7,7 @@ from typing import Any, TypeVar, cast
from fitbit import Fitbit
from fitbit.exceptions import HTTPException, HTTPUnauthorized
from requests.exceptions import ConnectionError as RequestsConnectionError
from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.core import HomeAssistant
@ -132,6 +133,9 @@ class FitbitApi(ABC):
"""Run client command."""
try:
return await self._hass.async_add_executor_job(func)
except RequestsConnectionError as err:
_LOGGER.debug("Connection error to fitbit API: %s", err)
raise FitbitApiException("Connection error to fitbit API") from err
except HTTPUnauthorized as err:
_LOGGER.debug("Unauthorized error from fitbit API: %s", err)
raise FitbitAuthException("Authentication error from fitbit API") from err

View File

@ -6,6 +6,7 @@ from http import HTTPStatus
from typing import Any
import pytest
from requests.exceptions import ConnectionError as RequestsConnectionError
from requests_mock.mocker import Mocker
from syrupy.assertion import SnapshotAssertion
@ -599,10 +600,11 @@ async def test_settings_scope_config_entry(
@pytest.mark.parametrize(
("scopes", "server_status"),
("scopes", "request_condition"),
[
(["heartrate"], HTTPStatus.INTERNAL_SERVER_ERROR),
(["heartrate"], HTTPStatus.BAD_REQUEST),
(["heartrate"], {"status_code": HTTPStatus.INTERNAL_SERVER_ERROR}),
(["heartrate"], {"status_code": HTTPStatus.BAD_REQUEST}),
(["heartrate"], {"exc": RequestsConnectionError}),
],
)
async def test_sensor_update_failed(
@ -610,14 +612,14 @@ async def test_sensor_update_failed(
setup_credentials: None,
integration_setup: Callable[[], Awaitable[bool]],
requests_mock: Mocker,
server_status: HTTPStatus,
request_condition: dict[str, Any],
) -> None:
"""Test a failed sensor update when talking to the API."""
requests_mock.register_uri(
"GET",
TIMESERIES_API_URL_FORMAT.format(resource="activities/heart"),
status_code=server_status,
**request_condition,
)
assert await integration_setup()