2022-03-31 12:28:19 +00:00
|
|
|
"""The tests for update recorder."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from datetime import timedelta
|
|
|
|
|
2023-02-17 15:40:46 +00:00
|
|
|
from homeassistant.components.recorder import Recorder
|
2023-03-12 02:51:16 +00:00
|
|
|
from homeassistant.components.recorder.history import get_significant_states
|
2022-03-31 12:28:19 +00:00
|
|
|
from homeassistant.components.update.const import (
|
|
|
|
ATTR_IN_PROGRESS,
|
2022-04-01 18:11:17 +00:00
|
|
|
ATTR_INSTALLED_VERSION,
|
2022-03-31 12:28:19 +00:00
|
|
|
ATTR_RELEASE_SUMMARY,
|
|
|
|
DOMAIN,
|
|
|
|
)
|
2022-04-03 19:41:51 +00:00
|
|
|
from homeassistant.const import ATTR_ENTITY_PICTURE, CONF_PLATFORM
|
2023-03-12 02:51:16 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-03-31 12:28:19 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from homeassistant.util import dt as dt_util
|
|
|
|
|
2022-04-23 05:29:44 +00:00
|
|
|
from tests.common import async_fire_time_changed
|
2022-04-25 10:04:47 +00:00
|
|
|
from tests.components.recorder.common import async_wait_recording_done
|
2022-03-31 12:28:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_exclude_attributes(
|
2023-02-17 15:40:46 +00:00
|
|
|
recorder_mock: Recorder, hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
) -> None:
|
2022-03-31 12:28:19 +00:00
|
|
|
"""Test update attributes to be excluded."""
|
2023-03-12 02:51:16 +00:00
|
|
|
now = dt_util.utcnow()
|
2022-03-31 12:28:19 +00:00
|
|
|
platform = getattr(hass.components, f"test.{DOMAIN}")
|
|
|
|
platform.init()
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
state = hass.states.get("update.update_already_in_progress")
|
|
|
|
assert state.attributes[ATTR_IN_PROGRESS] == 50
|
2022-04-03 19:41:51 +00:00
|
|
|
assert (
|
|
|
|
state.attributes[ATTR_ENTITY_PICTURE]
|
|
|
|
== "https://brands.home-assistant.io/_/test/icon.png"
|
|
|
|
)
|
2022-03-31 12:28:19 +00:00
|
|
|
await async_setup_component(hass, DOMAIN, {})
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=5))
|
|
|
|
await hass.async_block_till_done()
|
2022-04-25 10:04:47 +00:00
|
|
|
await async_wait_recording_done(hass)
|
2022-03-31 12:28:19 +00:00
|
|
|
|
2023-04-09 02:14:44 +00:00
|
|
|
states = await hass.async_add_executor_job(
|
|
|
|
get_significant_states, hass, now, None, hass.states.async_entity_ids()
|
|
|
|
)
|
2023-03-12 02:51:16 +00:00
|
|
|
assert len(states) >= 1
|
|
|
|
for entity_states in states.values():
|
|
|
|
for state in entity_states:
|
|
|
|
assert ATTR_ENTITY_PICTURE not in state.attributes
|
|
|
|
assert ATTR_IN_PROGRESS not in state.attributes
|
|
|
|
assert ATTR_RELEASE_SUMMARY not in state.attributes
|
|
|
|
assert ATTR_INSTALLED_VERSION in state.attributes
|