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

+11 -3
View File
@@ -26,6 +26,7 @@ from homeassistant.helpers.entity import async_generate_entity_id
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.script import Script
from . import async_setup_platform_reloadable
from .const import CONF_AVAILABILITY_TEMPLATE
from .template_entity import TemplateEntity
@@ -54,8 +55,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Template switch."""
async def async_create_entities(hass, config):
"""Create the Template switches."""
switches = []
for device, device_config in config[CONF_SWITCHES].items():
@@ -83,7 +84,14 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
)
)
async_add_entities(switches)
return switches
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the template switches."""
await async_setup_platform_reloadable(hass)
async_add_entities(await async_create_entities(hass, config))
class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity):