diff --git a/tests/common.py b/tests/common.py index ca164fcaaf..c359f5c532 100644 --- a/tests/common.py +++ b/tests/common.py @@ -63,6 +63,7 @@ from homeassistant.helpers import ( restore_state, restore_state as rs, storage, + template, ) from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.json import JSONEncoder @@ -267,6 +268,7 @@ async def async_test_home_assistant(event_loop, load_registries=True): ir.async_load(hass), rs.async_load(hass), ) + template.async_setup(hass) hass.data[bootstrap.DATA_REGISTRIES_LOADED] = None hass.state = CoreState.running diff --git a/tests/components/persistent_notification/test_init.py b/tests/components/persistent_notification/test_init.py index 7fd8b00d3e..d11e9474e2 100644 --- a/tests/components/persistent_notification/test_init.py +++ b/tests/components/persistent_notification/test_init.py @@ -4,6 +4,7 @@ import pytest import homeassistant.components.persistent_notification as pn from homeassistant.components.websocket_api.const import TYPE_RESULT from homeassistant.core import HomeAssistant +from homeassistant.helpers.template import Template from homeassistant.setup import async_setup_component from tests.typing import WebSocketGenerator @@ -15,6 +16,29 @@ async def setup_integration(hass): assert await async_setup_component(hass, pn.DOMAIN, {}) +async def test_template_usage(hass: HomeAssistant) -> None: + """Test enumerating persistent notifications in a template.""" + await hass.services.async_call( + pn.DOMAIN, + "create", + {"notification_id": "Beer 2", "message": "test"}, + blocking=True, + ) + + result = Template("{{ persistent_notifications() | count }}", hass).async_render() + assert result == 1 + + await hass.services.async_call( + pn.DOMAIN, + "dismiss", + {"notification_id": "Beer 2"}, + blocking=True, + ) + + result = Template("{{ persistent_notifications() | count }}", hass).async_render() + assert result == 0 + + async def test_create(hass: HomeAssistant) -> None: """Test creating notification without title or notification id.""" notifications = pn._async_get_or_create_notifications(hass)