Make template entities reloadable (#39075)

* Make template entities reloadable

* Address review items
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-08-21 18:31:48 -05:00
1 parent 993088d26e
commit 83b9c6188d
20 files changed
+468 -43

No files matched your search

@@ -5,7 +5,7 @@ from typing import Any, Callable, Optional, Union
import voluptuous as vol
from homeassistant.core import EVENT_HOMEASSISTANT_START, callback
from homeassistant.core import EVENT_HOMEASSISTANT_START, CoreState, callback
from homeassistant.exceptions import TemplateError
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
@@ -232,7 +232,7 @@ class TemplateEntity(Entity):
attribute.async_setup()
self._template_attrs.append(attribute)
async def _async_template_startup(self, _) -> None:
async def _async_template_startup(self, *_) -> None:
# async_update will not write state
# until "add_complete" is set on the attribute
for attribute in self._template_attrs:
@@ -259,6 +259,9 @@ class TemplateEntity(Entity):
self.add_template_attribute(
"_entity_picture", self._entity_picture_template
)
if self.hass.state == CoreState.running:
await self._async_template_startup()
return
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_START, self._async_template_startup