Show a warning when no Withings data found (#103066)
This commit is contained in:
parent
0f72495a7d
commit
7319abcab0
2 changed files with 24 additions and 0 deletions
|
@ -40,6 +40,7 @@ from homeassistant.util import dt as dt_util
|
|||
from . import WithingsData
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
SCORE_POINTS,
|
||||
UOM_BEATS_PER_MINUTE,
|
||||
UOM_BREATHS_PER_MINUTE,
|
||||
|
@ -787,6 +788,11 @@ async def async_setup_entry(
|
|||
_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)
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from datetime import timedelta
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from aiowithings import Goals
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
@ -341,3 +342,20 @@ async def test_workout_sensors_created_when_receive_workout_data(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue