Improve handling of template platforms when entity extraction fails (#37831)

Most of the the template platforms would check for
extract_entities failing to extract entities and avoid
setting up a state change listner for MATCH_ALL after
extract_entities had warned that it could not extract
the entities and updates would need to be done manually.
This protection has been extended to all template platforms.

Alter the behavior of extract_entities to return the
successfully extracted entities if one or more templates
fail extraction instead of returning MATCH_ALL
This commit is contained in:
J. Nick Koston 2020-07-14 19:34:35 -10:00 committed by GitHub
parent e938dcfbda
commit 44fefb3216
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 63 additions and 44 deletions

View file

@ -23,6 +23,7 @@ from homeassistant.const import (
CONF_FRIENDLY_NAME,
CONF_VALUE_TEMPLATE,
EVENT_HOMEASSISTANT_START,
MATCH_ALL,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
@ -313,16 +314,18 @@ class TemplateFan(FanEntity):
"""Register callbacks."""
@callback
def template_fan_state_listener(entity, old_state, new_state):
def template_fan_state_listener(event):
"""Handle target device state changes."""
self.async_schedule_update_ha_state(True)
@callback
def template_fan_startup(event):
"""Update template on startup."""
self.hass.helpers.event.async_track_state_change(
self._entities, template_fan_state_listener
)
if self._entities != MATCH_ALL:
# Track state change only for valid templates
self.hass.helpers.event.async_track_state_change_event(
self._entities, template_fan_state_listener
)
self.async_schedule_update_ha_state(True)