Fix duplicate template handling in Persistent Notifications (#47217)

This commit is contained in:
Franck Nijhof 2021-03-02 01:27:26 +01:00 committed by GitHub
parent cc6293623f
commit 4f9f870e7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import TemplateError from homeassistant.exceptions import TemplateError
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity import async_generate_entity_id from homeassistant.helpers.entity import async_generate_entity_id
from homeassistant.helpers.template import Template
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
from homeassistant.util import slugify from homeassistant.util import slugify
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -35,8 +36,8 @@ SERVICE_MARK_READ = "mark_read"
SCHEMA_SERVICE_CREATE = vol.Schema( SCHEMA_SERVICE_CREATE = vol.Schema(
{ {
vol.Required(ATTR_MESSAGE): cv.template, vol.Required(ATTR_MESSAGE): vol.Any(cv.dynamic_template, cv.string),
vol.Optional(ATTR_TITLE): cv.template, vol.Optional(ATTR_TITLE): vol.Any(cv.dynamic_template, cv.string),
vol.Optional(ATTR_NOTIFICATION_ID): cv.string, vol.Optional(ATTR_NOTIFICATION_ID): cv.string,
} }
) )
@ -118,6 +119,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
attr = {} attr = {}
if title is not None: if title is not None:
if isinstance(title, Template):
try: try:
title.hass = hass title.hass = hass
title = title.async_render(parse_result=False) title = title.async_render(parse_result=False)
@ -128,6 +130,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
attr[ATTR_TITLE] = title attr[ATTR_TITLE] = title
attr[ATTR_FRIENDLY_NAME] = title attr[ATTR_FRIENDLY_NAME] = title
if isinstance(message, Template):
try: try:
message.hass = hass message.hass = hass
message = message.async_render(parse_result=False) message = message.async_render(parse_result=False)