From 7e366ebb90a42567dda79eafd1cfdce6c314a3d8 Mon Sep 17 00:00:00 2001 From: Sir GoodEnough Date: Sat, 23 Sep 2023 21:01:26 -0500 Subject: [PATCH] Improve error proofing. Ensure list as input. --- README.md | 2 +- availability_template.jinja | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eacf653..d69dea5 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ If you cannot see templates in your HACS listing, you *may* need to enable 'expe # Availability Test -## `avail([entity1, ...])` +## `avail([entity1, entity2, /])` This expects a list of entities. diff --git a/availability_template.jinja b/availability_template.jinja index 548102f..d042de6 100644 --- a/availability_template.jinja +++ b/availability_template.jinja @@ -13,7 +13,10 @@ {% from 'availability_template.jinja' import avail %} {{- avail(['entity_1','entity_2']) | bool -}} #} - {%- if entity_list is iterable -%} + {# First tests to make sure this is a list #} + {%- if entity_list is iterable and + (entity_list is not string and entity_list is not mapping) + -%} {{- entity_list | map('states') | reject('in', ['unknown','unavailable','','none']) | list | count == entity_list | count -}} {%- else -%}