Skip template result parsing in several places (#42408)
* Skip template result parsing in several places
* Adjust alert integration
* Adjust Alexa integration
* Adjust apns integration
* Adjust arest integration
* Adjust dialogflow integration
* Adjust generic camera integration
* Adjust imap email content integration
* Adjust InfluxDB integration
* Adjust intent integration
* Adjust logbook integration
* Adjust HP ILO integration
* Adjust manual alarm control panel integration
* Adjust manual mqtt alarm control panel integration
* Adjust minio integration
* Adjust mqtt integration
* Adjust notify integration
* Adjust persistent notification integration
* Adjust rest integration
* Adjust rss feed template integration
* Adjust slack integration
* Adjust Xiaomi integration
* Adjust TCP integration
* Adjust Telegram Bot integration
* Bump CI cache version
* Revert "Bump CI cache version"
This reverts commit 875efe58cf
.
* Adjust demo tests
pull/42516/head
parent
287b33eef3
commit
326d36d303
|
@ -276,7 +276,7 @@ class Alert(ToggleEntity):
|
|||
self._send_done_message = True
|
||||
|
||||
if self._message_template is not None:
|
||||
message = self._message_template.async_render()
|
||||
message = self._message_template.async_render(parse_result=False)
|
||||
else:
|
||||
message = self._name
|
||||
|
||||
|
@ -291,7 +291,7 @@ class Alert(ToggleEntity):
|
|||
if self._done_message_template is None:
|
||||
return
|
||||
|
||||
message = self._done_message_template.async_render()
|
||||
message = self._done_message_template.async_render(parse_result=False)
|
||||
|
||||
await self._send_notification_message(message)
|
||||
|
||||
|
@ -300,7 +300,7 @@ class Alert(ToggleEntity):
|
|||
msg_payload = {ATTR_MESSAGE: message}
|
||||
|
||||
if self._title_template is not None:
|
||||
title = self._title_template.async_render()
|
||||
title = self._title_template.async_render(parse_result=False)
|
||||
msg_payload.update({ATTR_TITLE: title})
|
||||
if self._data:
|
||||
msg_payload.update({ATTR_DATA: self._data})
|
||||
|
|
|
@ -80,13 +80,17 @@ class AlexaFlashBriefingView(http.HomeAssistantView):
|
|||
output = {}
|
||||
if item.get(CONF_TITLE) is not None:
|
||||
if isinstance(item.get(CONF_TITLE), template.Template):
|
||||
output[ATTR_TITLE_TEXT] = item[CONF_TITLE].async_render()
|
||||
output[ATTR_TITLE_TEXT] = item[CONF_TITLE].async_render(
|
||||
parse_result=False
|
||||
)
|
||||
else:
|
||||
output[ATTR_TITLE_TEXT] = item.get(CONF_TITLE)
|
||||
|
||||
if item.get(CONF_TEXT) is not None:
|
||||
if isinstance(item.get(CONF_TEXT), template.Template):
|
||||
output[ATTR_MAIN_TEXT] = item[CONF_TEXT].async_render()
|
||||
output[ATTR_MAIN_TEXT] = item[CONF_TEXT].async_render(
|
||||
parse_result=False
|
||||
)
|
||||
else:
|
||||
output[ATTR_MAIN_TEXT] = item.get(CONF_TEXT)
|
||||
|
||||
|
@ -97,13 +101,17 @@ class AlexaFlashBriefingView(http.HomeAssistantView):
|
|||
|
||||
if item.get(CONF_AUDIO) is not None:
|
||||
if isinstance(item.get(CONF_AUDIO), template.Template):
|
||||
output[ATTR_STREAM_URL] = item[CONF_AUDIO].async_render()
|
||||
output[ATTR_STREAM_URL] = item[CONF_AUDIO].async_render(
|
||||
parse_result=False
|
||||
)
|
||||
else:
|
||||
output[ATTR_STREAM_URL] = item.get(CONF_AUDIO)
|
||||
|
||||
if item.get(CONF_DISPLAY_URL) is not None:
|
||||
if isinstance(item.get(CONF_DISPLAY_URL), template.Template):
|
||||
output[ATTR_REDIRECTION_URL] = item[CONF_DISPLAY_URL].async_render()
|
||||
output[ATTR_REDIRECTION_URL] = item[CONF_DISPLAY_URL].async_render(
|
||||
parse_result=False
|
||||
)
|
||||
else:
|
||||
output[ATTR_REDIRECTION_URL] = item.get(CONF_DISPLAY_URL)
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ class AlexaResponse:
|
|||
|
||||
self.reprompt = {
|
||||
"type": speech_type.value,
|
||||
key: text.async_render(self.variables),
|
||||
key: text.async_render(self.variables, parse_result=False),
|
||||
}
|
||||
|
||||
def as_dict(self):
|
||||
|
|
|
@ -229,7 +229,7 @@ class ApnsNotificationService(BaseNotificationService):
|
|||
if isinstance(message, str):
|
||||
rendered_message = message
|
||||
elif isinstance(message, template_helper.Template):
|
||||
rendered_message = message.render()
|
||||
rendered_message = message.render(parse_result=False)
|
||||
else:
|
||||
rendered_message = ""
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
|
||||
def _render(value):
|
||||
try:
|
||||
return value_template.async_render({"value": value})
|
||||
return value_template.async_render({"value": value}, parse_result=False)
|
||||
except TemplateError:
|
||||
_LOGGER.exception("Error parsing value")
|
||||
return value
|
||||
|
|
|
@ -161,7 +161,7 @@ class DialogflowResponse:
|
|||
assert self.speech is None
|
||||
|
||||
if isinstance(text, template.Template):
|
||||
text = text.async_render(self.parameters)
|
||||
text = text.async_render(self.parameters, parse_result=False)
|
||||
|
||||
self.speech = text
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ class GenericCamera(Camera):
|
|||
async def async_camera_image(self):
|
||||
"""Return a still image response from the camera."""
|
||||
try:
|
||||
url = self._still_image_url.async_render()
|
||||
url = self._still_image_url.async_render(parse_result=False)
|
||||
except TemplateError as err:
|
||||
_LOGGER.error("Error parsing template %s: %s", self._still_image_url, err)
|
||||
return self._last_image
|
||||
|
@ -178,7 +178,7 @@ class GenericCamera(Camera):
|
|||
return None
|
||||
|
||||
try:
|
||||
return self._stream_source.async_render()
|
||||
return self._stream_source.async_render(parse_result=False)
|
||||
except TemplateError as err:
|
||||
_LOGGER.error("Error parsing template %s: %s", self._stream_source, err)
|
||||
return None
|
||||
|
|
|
@ -157,7 +157,9 @@ class HpIloSensor(Entity):
|
|||
ilo_data = getattr(self.hp_ilo_data.data, self._ilo_function)()
|
||||
|
||||
if self._sensor_value_template is not None:
|
||||
ilo_data = self._sensor_value_template.render(ilo_data=ilo_data)
|
||||
ilo_data = self._sensor_value_template.render(
|
||||
ilo_data=ilo_data, parse_result=False
|
||||
)
|
||||
|
||||
self._state = ilo_data
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ class EmailContentSensor(Entity):
|
|||
ATTR_DATE: email_message["Date"],
|
||||
ATTR_BODY: EmailContentSensor.get_msg_text(email_message),
|
||||
}
|
||||
return self._value_template.render(variables)
|
||||
return self._value_template.render(variables, parse_result=False)
|
||||
|
||||
def sender_allowed(self, email_message):
|
||||
"""Check if the sender is in the allowed senders list."""
|
||||
|
|
|
@ -268,7 +268,7 @@ class InfluxFluxSensorData:
|
|||
"""Get the latest data by querying influx."""
|
||||
_LOGGER.debug(RENDERING_QUERY_MESSAGE, self.query)
|
||||
try:
|
||||
rendered_query = self.query.render()
|
||||
rendered_query = self.query.render(parse_result=False)
|
||||
except TemplateError as ex:
|
||||
_LOGGER.error(RENDERING_QUERY_ERROR_MESSAGE, ex)
|
||||
return
|
||||
|
@ -312,7 +312,7 @@ class InfluxQLSensorData:
|
|||
"""Get the latest data with a shell command."""
|
||||
_LOGGER.debug(RENDERING_WHERE_MESSAGE, self.where)
|
||||
try:
|
||||
where_clause = self.where.render()
|
||||
where_clause = self.where.render(parse_result=False)
|
||||
except TemplateError as ex:
|
||||
_LOGGER.error(RENDERING_WHERE_ERROR_MESSAGE, ex)
|
||||
return
|
||||
|
|
|
@ -87,13 +87,14 @@ class ScriptIntentHandler(intent.IntentHandler):
|
|||
|
||||
if speech is not None:
|
||||
response.async_set_speech(
|
||||
speech[CONF_TEXT].async_render(slots), speech[CONF_TYPE]
|
||||
speech[CONF_TEXT].async_render(slots, parse_result=False),
|
||||
speech[CONF_TYPE],
|
||||
)
|
||||
|
||||
if card is not None:
|
||||
response.async_set_card(
|
||||
card[CONF_TITLE].async_render(slots),
|
||||
card[CONF_CONTENT].async_render(slots),
|
||||
card[CONF_TITLE].async_render(slots, parse_result=False),
|
||||
card[CONF_CONTENT].async_render(slots, parse_result=False),
|
||||
card[CONF_TYPE],
|
||||
)
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ async def async_setup(hass, config):
|
|||
domain = DOMAIN
|
||||
|
||||
message.hass = hass
|
||||
message = message.async_render()
|
||||
message = message.async_render(parse_result=False)
|
||||
async_log_entry(hass, name, message, domain, entity_id)
|
||||
|
||||
hass.components.frontend.async_register_built_in_panel(
|
||||
|
|
|
@ -385,7 +385,9 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||
if isinstance(self._code, str):
|
||||
alarm_code = self._code
|
||||
else:
|
||||
alarm_code = self._code.render(from_state=self._state, to_state=state)
|
||||
alarm_code = self._code.render(
|
||||
parse_result=False, from_state=self._state, to_state=state
|
||||
)
|
||||
check = not alarm_code or code == alarm_code
|
||||
if not check:
|
||||
_LOGGER.warning("Invalid code given for %s", state)
|
||||
|
|
|
@ -406,7 +406,9 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||
if isinstance(self._code, str):
|
||||
alarm_code = self._code
|
||||
else:
|
||||
alarm_code = self._code.render(from_state=self._state, to_state=state)
|
||||
alarm_code = self._code.render(
|
||||
from_state=self._state, to_state=state, parse_result=False
|
||||
)
|
||||
check = not alarm_code or code == alarm_code
|
||||
if not check:
|
||||
_LOGGER.warning("Invalid code given for %s", state)
|
||||
|
|
|
@ -124,7 +124,7 @@ def setup(hass, config):
|
|||
def _render_service_value(service, key):
|
||||
value = service.data[key]
|
||||
value.hass = hass
|
||||
return value.async_render()
|
||||
return value.async_render(parse_result=False)
|
||||
|
||||
def put_file(service):
|
||||
"""Upload file service."""
|
||||
|
|
|
@ -338,7 +338,7 @@ class MqttAlarm(
|
|||
"""Publish via mqtt."""
|
||||
command_template = self._config[CONF_COMMAND_TEMPLATE]
|
||||
values = {"action": action, "code": code}
|
||||
payload = command_template.async_render(**values)
|
||||
payload = command_template.async_render(**values, parse_result=False)
|
||||
mqtt.async_publish(
|
||||
self.hass,
|
||||
self._config[CONF_COMMAND_TOPIC],
|
||||
|
|
|
@ -557,7 +557,7 @@ class MqttCover(
|
|||
position = kwargs[ATTR_POSITION]
|
||||
percentage_position = position
|
||||
if set_position_template is not None:
|
||||
position = set_position_template.async_render(**kwargs)
|
||||
position = set_position_template.async_render(parse_result=False, **kwargs)
|
||||
else:
|
||||
position = self.find_in_range_from_percent(position, COVER_PAYLOAD)
|
||||
|
||||
|
|
|
@ -441,7 +441,9 @@ class MqttLightTemplate(
|
|||
mqtt.async_publish(
|
||||
self.hass,
|
||||
self._topics[CONF_COMMAND_TOPIC],
|
||||
self._templates[CONF_COMMAND_ON_TEMPLATE].async_render(**values),
|
||||
self._templates[CONF_COMMAND_ON_TEMPLATE].async_render(
|
||||
parse_result=False, **values
|
||||
),
|
||||
self._config[CONF_QOS],
|
||||
self._config[CONF_RETAIN],
|
||||
)
|
||||
|
@ -464,7 +466,9 @@ class MqttLightTemplate(
|
|||
mqtt.async_publish(
|
||||
self.hass,
|
||||
self._topics[CONF_COMMAND_TOPIC],
|
||||
self._templates[CONF_COMMAND_OFF_TEMPLATE].async_render(**values),
|
||||
self._templates[CONF_COMMAND_OFF_TEMPLATE].async_render(
|
||||
parse_result=False, **values
|
||||
),
|
||||
self._config[CONF_QOS],
|
||||
self._config[CONF_RETAIN],
|
||||
)
|
||||
|
|
|
@ -133,7 +133,7 @@ class BaseNotificationService:
|
|||
|
||||
if title:
|
||||
title.hass = self.hass
|
||||
kwargs[ATTR_TITLE] = title.async_render()
|
||||
kwargs[ATTR_TITLE] = title.async_render(parse_result=False)
|
||||
|
||||
if self._registered_targets.get(service.service) is not None:
|
||||
kwargs[ATTR_TARGET] = [self._registered_targets[service.service]]
|
||||
|
@ -141,7 +141,7 @@ class BaseNotificationService:
|
|||
kwargs[ATTR_TARGET] = service.data.get(ATTR_TARGET)
|
||||
|
||||
message.hass = self.hass
|
||||
kwargs[ATTR_MESSAGE] = message.async_render()
|
||||
kwargs[ATTR_MESSAGE] = message.async_render(parse_result=False)
|
||||
kwargs[ATTR_DATA] = service.data.get(ATTR_DATA)
|
||||
|
||||
await self.async_send_message(**kwargs)
|
||||
|
@ -229,12 +229,12 @@ async def async_setup(hass, config):
|
|||
payload = {}
|
||||
message = service.data[ATTR_MESSAGE]
|
||||
message.hass = hass
|
||||
payload[ATTR_MESSAGE] = message.async_render()
|
||||
payload[ATTR_MESSAGE] = message.async_render(parse_result=False)
|
||||
|
||||
title = service.data.get(ATTR_TITLE)
|
||||
if title:
|
||||
title.hass = hass
|
||||
payload[ATTR_TITLE] = title.async_render()
|
||||
payload[ATTR_TITLE] = title.async_render(parse_result=False)
|
||||
|
||||
await hass.services.async_call(
|
||||
pn.DOMAIN, pn.SERVICE_CREATE, payload, blocking=True
|
||||
|
|
|
@ -119,7 +119,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
|||
if title is not None:
|
||||
try:
|
||||
title.hass = hass
|
||||
title = title.async_render()
|
||||
title = title.async_render(parse_result=False)
|
||||
except TemplateError as ex:
|
||||
_LOGGER.error("Error rendering title %s: %s", title, ex)
|
||||
title = title.template
|
||||
|
@ -128,7 +128,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
|||
|
||||
try:
|
||||
message.hass = hass
|
||||
message = message.async_render()
|
||||
message = message.async_render(parse_result=False)
|
||||
except TemplateError as ex:
|
||||
_LOGGER.error("Error rendering message %s: %s", message, ex)
|
||||
message = message.template
|
||||
|
|
|
@ -84,7 +84,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
|
||||
if resource_template is not None:
|
||||
resource_template.hass = hass
|
||||
resource = resource_template.render()
|
||||
resource = resource_template.render(parse_result=False)
|
||||
|
||||
if value_template is not None:
|
||||
value_template.hass = hass
|
||||
|
@ -189,6 +189,6 @@ class RestBinarySensor(BinarySensorEntity):
|
|||
async def async_update(self):
|
||||
"""Get the latest data from REST API and updates the state."""
|
||||
if self._resource_template is not None:
|
||||
self.rest.set_url(self._resource_template.render())
|
||||
self.rest.set_url(self._resource_template.render(parse_result=False))
|
||||
|
||||
await self.rest.async_update()
|
||||
|
|
|
@ -163,7 +163,7 @@ class RestNotificationService(BaseNotificationService):
|
|||
key: _data_template_creator(item) for key, item in value.items()
|
||||
}
|
||||
value.hass = self._hass
|
||||
return value.async_render(kwargs)
|
||||
return value.async_render(kwargs, parse_result=False)
|
||||
|
||||
data.update(_data_template_creator(self._data_template))
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
|
||||
if resource_template is not None:
|
||||
resource_template.hass = hass
|
||||
resource = resource_template.render()
|
||||
resource = resource_template.render(parse_result=False)
|
||||
|
||||
if username and password:
|
||||
if config.get(CONF_AUTHENTICATION) == HTTP_DIGEST_AUTHENTICATION:
|
||||
|
@ -202,7 +202,7 @@ class RestSensor(Entity):
|
|||
async def async_update(self):
|
||||
"""Get the latest data from REST API and update the state."""
|
||||
if self._resource_template is not None:
|
||||
self.rest.set_url(self._resource_template.render())
|
||||
self.rest.set_url(self._resource_template.render(parse_result=False))
|
||||
|
||||
await self.rest.async_update()
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ class RestSwitch(SwitchEntity):
|
|||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
body_on_t = self._body_on.async_render()
|
||||
body_on_t = self._body_on.async_render(parse_result=False)
|
||||
|
||||
try:
|
||||
req = await self.set_device_state(body_on_t)
|
||||
|
@ -178,7 +178,7 @@ class RestSwitch(SwitchEntity):
|
|||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
body_off_t = self._body_off.async_render()
|
||||
body_off_t = self._body_off.async_render(parse_result=False)
|
||||
|
||||
try:
|
||||
req = await self.set_device_state(body_off_t)
|
||||
|
|
|
@ -93,17 +93,22 @@ async def async_setup(hass, config):
|
|||
payload = None
|
||||
if template_payload:
|
||||
payload = bytes(
|
||||
template_payload.async_render(variables=service.data), "utf-8"
|
||||
template_payload.async_render(
|
||||
variables=service.data, parse_result=False
|
||||
),
|
||||
"utf-8",
|
||||
)
|
||||
|
||||
request_url = template_url.async_render(variables=service.data)
|
||||
request_url = template_url.async_render(
|
||||
variables=service.data, parse_result=False
|
||||
)
|
||||
|
||||
headers = None
|
||||
if template_headers:
|
||||
headers = {}
|
||||
for header_name, template_header in template_headers.items():
|
||||
headers[header_name] = template_header.async_render(
|
||||
variables=service.data
|
||||
variables=service.data, parse_result=False
|
||||
)
|
||||
|
||||
if content_type:
|
||||
|
|
|
@ -83,17 +83,19 @@ class RssView(HomeAssistantView):
|
|||
|
||||
response += "<rss>\n"
|
||||
if self._title is not None:
|
||||
response += " <title>%s</title>\n" % escape(self._title.async_render())
|
||||
response += " <title>%s</title>\n" % escape(
|
||||
self._title.async_render(parse_result=False)
|
||||
)
|
||||
|
||||
for item in self._items:
|
||||
response += " <item>\n"
|
||||
if "title" in item:
|
||||
response += " <title>"
|
||||
response += escape(item["title"].async_render())
|
||||
response += escape(item["title"].async_render(parse_result=False))
|
||||
response += "</title>\n"
|
||||
if "description" in item:
|
||||
response += " <description>"
|
||||
response += escape(item["description"].async_render())
|
||||
response += escape(item["description"].async_render(parse_result=False))
|
||||
response += "</description>\n"
|
||||
response += " </item>\n"
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ def _async_templatize_blocks(hass, value):
|
|||
}
|
||||
|
||||
tmpl = template.Template(value, hass=hass)
|
||||
return tmpl.async_render()
|
||||
return tmpl.async_render(parse_result=False)
|
||||
|
||||
|
||||
class SlackNotificationService(BaseNotificationService):
|
||||
|
|
|
@ -136,7 +136,9 @@ class TcpSensor(Entity):
|
|||
|
||||
if self._config[CONF_VALUE_TEMPLATE] is not None:
|
||||
try:
|
||||
self._state = self._config[CONF_VALUE_TEMPLATE].render(value=value)
|
||||
self._state = self._config[CONF_VALUE_TEMPLATE].render(
|
||||
parse_result=False, value=value
|
||||
)
|
||||
return
|
||||
except TemplateError:
|
||||
_LOGGER.error(
|
||||
|
|
|
@ -329,7 +329,9 @@ async def async_setup(hass, config):
|
|||
else:
|
||||
attribute_templ.hass = hass
|
||||
try:
|
||||
data[attribute] = attribute_templ.async_render()
|
||||
data[attribute] = attribute_templ.async_render(
|
||||
parse_result=False
|
||||
)
|
||||
except TemplateError as exc:
|
||||
_LOGGER.error(
|
||||
"TemplateError in %s: %s -> %s",
|
||||
|
|
|
@ -142,7 +142,7 @@ class XiaomiCamera(Camera):
|
|||
"""Return a still image response from the camera."""
|
||||
|
||||
try:
|
||||
host = self.host.async_render()
|
||||
host = self.host.async_render(parse_result=False)
|
||||
except TemplateError as exc:
|
||||
_LOGGER.error("Error parsing template %s: %s", self.host, exc)
|
||||
return self._last_image
|
||||
|
|
|
@ -108,7 +108,7 @@ async def test_sending_templated_message(hass, events):
|
|||
await hass.async_block_till_done()
|
||||
last_event = events[-1]
|
||||
assert last_event.data[notify.ATTR_TITLE] == "temperature"
|
||||
assert last_event.data[notify.ATTR_MESSAGE] == 10
|
||||
assert last_event.data[notify.ATTR_MESSAGE] == "10"
|
||||
|
||||
|
||||
async def test_method_forwards_correct_data(hass, events):
|
||||
|
|
Loading…
Reference in New Issue