Defer template tracking setup until template entity start (#40388)

pull/40458/head
J. Nick Koston 2020-09-22 09:28:02 -05:00 committed by GitHub
parent 7029345b9d
commit f837da6fe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 9 deletions

View File

@ -213,7 +213,6 @@ class TemplateEntity(Entity):
attribute = _TemplateAttribute(
self, attribute, template, validator, on_update, none_on_template_error
)
attribute.async_setup()
self._template_attrs.setdefault(template, [])
self._template_attrs[template].append(attribute)
@ -252,22 +251,21 @@ class TemplateEntity(Entity):
event, update.template, update.last_result, update.result
)
if self._async_update:
self.async_write_ha_state()
self.async_write_ha_state()
async def _async_template_startup(self, *_) -> None:
# _handle_results will not write state until "_async_update" is set
template_var_tups = [
TrackTemplate(template, None) for template in self._template_attrs
]
template_var_tups = []
for template, attributes in self._template_attrs.items():
template_var_tups.append(TrackTemplate(template, None))
for attribute in attributes:
attribute.async_setup()
result_info = async_track_template_result(
self.hass, template_var_tups, self._handle_results
)
self.async_on_remove(result_info.async_remove)
result_info.async_refresh()
self.async_write_ha_state()
self._async_update = result_info.async_refresh
result_info.async_refresh()
async def async_added_to_hass(self) -> None:
"""Run when entity about to be added to hass."""