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:
parent
e938dcfbda
commit
44fefb3216
12 changed files with 63 additions and 44 deletions
|
@ -24,7 +24,10 @@ from homeassistant.core import callback
|
|||
from homeassistant.exceptions import TemplateError
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import async_generate_entity_id
|
||||
from homeassistant.helpers.event import async_track_same_state, async_track_state_change
|
||||
from homeassistant.helpers.event import (
|
||||
async_track_same_state,
|
||||
async_track_state_change_event,
|
||||
)
|
||||
|
||||
from . import extract_entities, initialise_templates
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE
|
||||
|
@ -148,7 +151,7 @@ class BinarySensorTemplate(BinarySensorEntity):
|
|||
"""Register callbacks."""
|
||||
|
||||
@callback
|
||||
def template_bsensor_state_listener(entity, old_state, new_state):
|
||||
def template_bsensor_state_listener(event):
|
||||
"""Handle the target device state changes."""
|
||||
self.async_check_state()
|
||||
|
||||
|
@ -157,7 +160,7 @@ class BinarySensorTemplate(BinarySensorEntity):
|
|||
"""Update template on startup."""
|
||||
if self._entities != MATCH_ALL:
|
||||
# Track state change only for valid templates
|
||||
async_track_state_change(
|
||||
async_track_state_change_event(
|
||||
self.hass, self._entities, template_bsensor_state_listener
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue