Clean up template (#46509)

This commit is contained in:
tkdrob 2021-02-14 06:16:30 -05:00 committed by GitHub
parent 811e1cc3e6
commit 2c3a2bd35e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 1 additions and 25 deletions

View file

@ -7,13 +7,11 @@ from .const import DOMAIN, EVENT_TEMPLATE_RELOADED, PLATFORMS
async def async_setup_reload_service(hass):
"""Create the reload service for the template domain."""
if hass.services.has_service(DOMAIN, SERVICE_RELOAD):
return
async def _reload_config(call):
"""Reload the template platform config."""
await async_reload_integration_platforms(hass, DOMAIN, PLATFORMS)
hass.bus.async_fire(EVENT_TEMPLATE_RELOADED, context=call.context)

View file

@ -81,7 +81,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
async def _async_create_entities(hass, config):
"""Create Template Alarm Control Panels."""
alarm_control_panels = []
for device, device_config in config[CONF_ALARM_CONTROL_PANELS].items():
@ -114,7 +113,6 @@ async def _async_create_entities(hass, config):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Template Alarm Control Panels."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config))

View file

@ -97,7 +97,6 @@ async def _async_create_entities(hass, config):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the template binary sensors."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config))
@ -141,7 +140,6 @@ class BinarySensorTemplate(TemplateEntity, BinarySensorEntity):
async def async_added_to_hass(self):
"""Register callbacks."""
self.add_template_attribute("_state", self._template, None, self._update_state)
if self._delay_on_raw is not None:

View file

@ -20,6 +20,7 @@ from homeassistant.components.cover import (
CoverEntity,
)
from homeassistant.const import (
CONF_COVERS,
CONF_DEVICE_CLASS,
CONF_ENTITY_ID,
CONF_ENTITY_PICTURE_TEMPLATE,
@ -53,8 +54,6 @@ _VALID_STATES = [
"false",
]
CONF_COVERS = "covers"
CONF_POSITION_TEMPLATE = "position_template"
CONF_TILT_TEMPLATE = "tilt_template"
OPEN_ACTION = "open_cover"
@ -161,7 +160,6 @@ async def _async_create_entities(hass, config):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Template cover."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config))
@ -228,7 +226,6 @@ class CoverTemplate(TemplateEntity, CoverEntity):
async def async_added_to_hass(self):
"""Register callbacks."""
if self._template:
self.add_template_attribute(
"_position", self._template, None, self._update_state

View file

@ -159,7 +159,6 @@ async def _async_create_entities(hass, config):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the template fans."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config))

View file

@ -137,7 +137,6 @@ async def _async_create_entities(hass, config):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the template lights."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config))
@ -259,7 +258,6 @@ class LightTemplate(TemplateEntity, LightEntity):
async def async_added_to_hass(self):
"""Register callbacks."""
if self._template:
self.add_template_attribute(
"_state", self._template, None, self._update_state
@ -404,7 +402,6 @@ class LightTemplate(TemplateEntity, LightEntity):
@callback
def _update_state(self, result):
"""Update the state from the template."""
if isinstance(result, TemplateError):
# This behavior is legacy
self._state = False
@ -431,7 +428,6 @@ class LightTemplate(TemplateEntity, LightEntity):
@callback
def _update_temperature(self, render):
"""Update the temperature from the template."""
try:
if render in ("None", ""):
self._temperature = None

View file

@ -60,7 +60,6 @@ async def _async_create_entities(hass, config):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the template lock."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config))
@ -129,7 +128,6 @@ class TemplateLock(TemplateEntity, LockEntity):
async def async_added_to_hass(self):
"""Register callbacks."""
self.add_template_attribute(
"_state", self._state_template, None, self._update_state
)

View file

@ -59,7 +59,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
async def _async_create_entities(hass, config):
"""Create the template sensors."""
sensors = []
for device, device_config in config[CONF_SENSORS].items():
@ -96,7 +95,6 @@ async def _async_create_entities(hass, config):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the template sensors."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config))
@ -140,7 +138,6 @@ class SensorTemplate(TemplateEntity, Entity):
async def async_added_to_hass(self):
"""Register callbacks."""
self.add_template_attribute("_state", self._template, None, self._update_state)
if self._friendly_name_template is not None:
self.add_template_attribute("_name", self._friendly_name_template)

View file

@ -90,7 +90,6 @@ async def _async_create_entities(hass, config):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the template switches."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config))
@ -147,7 +146,6 @@ class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity):
async def async_added_to_hass(self):
"""Register callbacks."""
if self._template is None:
# restore state after startup

View file

@ -223,7 +223,6 @@ class TemplateEntity(Entity):
updates: List[TrackTemplateResult],
) -> None:
"""Call back the results to the attributes."""
if event:
self.async_set_context(event.context)

View file

@ -147,7 +147,6 @@ async def _async_create_entities(hass, config):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the template vacuums."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config))
@ -337,7 +336,6 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity):
async def async_added_to_hass(self):
"""Register callbacks."""
if self._template is not None:
self.add_template_attribute(
"_state", self._template, None, self._update_state