Template sensors to not track all state changes (#17276)

* Disable template sensor match all

* Only manual update template sensors that match all
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2018-10-10 13:49:15 +02:00
1 parent e5c3a4be80
commit a1dac28e4b
2 files changed
+107 -11

No files matched your search

+22 -4
View File
@@ -57,22 +57,36 @@ async def async_setup_platform(hass, config, async_add_entities,
entity_ids = set()
manual_entity_ids = device_config.get(ATTR_ENTITY_ID)
invalid_templates = []
for template in (state_template, icon_template,
entity_picture_template, friendly_name_template):
for tpl_name, template in (
(CONF_VALUE_TEMPLATE, state_template),
(CONF_ICON_TEMPLATE, icon_template),
(CONF_ENTITY_PICTURE_TEMPLATE, entity_picture_template),
(CONF_FRIENDLY_NAME_TEMPLATE, friendly_name_template),
):
if template is None:
continue
template.hass = hass
if entity_ids == MATCH_ALL or manual_entity_ids is not None:
if manual_entity_ids is not None:
continue
template_entity_ids = template.extract_entities()
if template_entity_ids == MATCH_ALL:
entity_ids = MATCH_ALL
else:
# Cut off _template from name
invalid_templates.append(tpl_name[:-9])
elif entity_ids != MATCH_ALL:
entity_ids |= set(template_entity_ids)
if invalid_templates:
_LOGGER.warning(
'Template sensor %s has no entity ids configured to track nor'
' were we able to extract the entities to track from the %s '
'template(s). This entity will only be able to be updated '
'manually.', device, ', '.join(invalid_templates))
if manual_entity_ids is not None:
entity_ids = manual_entity_ids
elif entity_ids != MATCH_ALL:
@@ -123,6 +137,10 @@ class SensorTemplate(Entity):
async def async_added_to_hass(self):
"""Register callbacks."""
# We don't render on every update
if self._entities == MATCH_ALL:
return
@callback
def template_sensor_state_listener(entity, old_state, new_state):
"""Handle device state changes."""