Show a warning when no Withings data found (#103066)

This commit is contained in:
Joost Lekkerkerker 2023-10-30 19:40:27 +01:00 committed by GitHub
parent 0f72495a7d
commit 7319abcab0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -40,6 +40,7 @@ from homeassistant.util import dt as dt_util
from . import WithingsData from . import WithingsData
from .const import ( from .const import (
DOMAIN, DOMAIN,
LOGGER,
SCORE_POINTS, SCORE_POINTS,
UOM_BEATS_PER_MINUTE, UOM_BEATS_PER_MINUTE,
UOM_BREATHS_PER_MINUTE, UOM_BREATHS_PER_MINUTE,
@ -787,6 +788,11 @@ async def async_setup_entry(
_async_add_workout_entities _async_add_workout_entities
) )
if not entities:
LOGGER.warning(
"No data found for Withings entry %s, sensors will be added when new data is available"
)
async_add_entities(entities) async_add_entities(entities)

View file

@ -2,6 +2,7 @@
from datetime import timedelta from datetime import timedelta
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from aiowithings import Goals
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
from syrupy import SnapshotAssertion from syrupy import SnapshotAssertion
@ -341,3 +342,20 @@ async def test_workout_sensors_created_when_receive_workout_data(
await hass.async_block_till_done() await hass.async_block_till_done()
assert hass.states.get("sensor.henk_last_workout_type") assert hass.states.get("sensor.henk_last_workout_type")
async def test_warning_if_no_entities_created(
hass: HomeAssistant,
withings: AsyncMock,
polling_config_entry: MockConfigEntry,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test we log a warning if no entities are created at startup."""
withings.get_workouts_in_period.return_value = []
withings.get_goals.return_value = Goals(None, None, None)
withings.get_measurement_in_period.return_value = []
withings.get_sleep_summary_since.return_value = []
withings.get_activities_since.return_value = []
await setup_integration(hass, polling_config_entry, False)
assert "No data found for Withings entry" in caplog.text