core/tests/components/calendar/test_recorder.py

53 lines
1.7 KiB
Python
Raw Normal View History

"""The tests for calendar recorder."""
from datetime import timedelta
from typing import Any
import pytest
from homeassistant.components.recorder import Recorder
from homeassistant.components.recorder.history import get_significant_states
from homeassistant.const import ATTR_FRIENDLY_NAME
from homeassistant.core import HomeAssistant
from homeassistant.util import dt as dt_util
from .conftest import MockCalendarEntity, create_mock_platform
from tests.common import async_fire_time_changed
from tests.components.recorder.common import async_wait_recording_done
@pytest.fixture(autouse=True)
async def mock_setup_dependencies(
recorder_mock: Recorder,
hass: HomeAssistant,
set_time_zone: Any,
mock_setup_integration: None,
test_entities: list[MockCalendarEntity],
) -> None:
"""Fixture that ensures the recorder is setup in the right order."""
await create_mock_platform(hass, test_entities)
async def test_exclude_attributes(hass: HomeAssistant) -> None:
2023-02-17 14:22:15 +00:00
"""Test sensor attributes to be excluded."""
now = dt_util.utcnow()
state = hass.states.get("calendar.calendar_1")
assert state
assert ATTR_FRIENDLY_NAME in state.attributes
assert "description" in state.attributes
# calendar.calendar_1
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5))
await hass.async_block_till_done()
await async_wait_recording_done(hass)
states = await hass.async_add_executor_job(
get_significant_states, hass, now, None, hass.states.async_entity_ids()
)
assert len(states) > 1
for entity_states in states.values():
for state in entity_states:
assert ATTR_FRIENDLY_NAME in state.attributes
assert "description" not in state.attributes