Skip to content

Commit

Permalink
Merge pull request #1 from SirGoodenough/New-List-Test
Browse files Browse the repository at this point in the history
change data valid to use new list test
  • Loading branch information
SirGoodenough authored Nov 14, 2023
2 parents ef3df63 + ec1a076 commit d535fd6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Templates are available for testing both True and False separately, and you can

The main reason for using this template is not because it's complicated, it's because the logic check is something you may be using over and over when you are dealing with automations, so being able to repeat the same action over and over is better if there is 1 place in your project the code exists. If you are only going to use this template in one place in your code, just copy the template and paste it in there directly for simplicity.

This requires HomeAssistant version 2023.11.0 or greater due to the use of the list test in the code.

# Installation

Install this in HACS or download the `logic_chekr.jinja` from this repository and place the files into your `config\custom_templates` directory.
Expand Down
36 changes: 18 additions & 18 deletions logic_chekr.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Items that do not evaluate as bool will be defaulted to null/undefined.
If there are one or more that match,
True is returned, else False, defaults to False.
homeassistant:
min_version: 2023.11.0
REMEMBER!!
This always returns text, so cast to bool on the other end to be certain
of the result.
Expand All @@ -18,9 +20,7 @@
{{- true_any(['entity_1','entity_2']) | bool -}}
#}
{# 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)
-%}
{%- if entity_list is list -%}
{{- entity_list | map('states')
| map('bool', null) | select('eq', True)
| list | count > 0 -}}
Expand All @@ -39,6 +39,8 @@
Items that do not evaluate as bool will be defaulted to null/undefined.
If there are one or more that match,
True is returned, else False, defaults to False.
homeassistant:
min_version: 2023.11.0
REMEMBER!!
This always returns text, so cast to bool on the other end to be certain
of the result.
Expand All @@ -49,9 +51,7 @@
{{- false_any(['entity_1','entity_2']) | bool -}}
#}
{# 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)
-%}
{%- if entity_list is list -%}
{{- entity_list | map('states')
| map('bool', null) | select('eq', False)
| list | count > 0 -}}
Expand All @@ -70,6 +70,8 @@
Items that do not evaluate as bool will be defaulted to null/undefined.
If there is only one that matches,
True is returned, else False, defaults to False.
homeassistant:
min_version: 2023.11.0
REMEMBER!!
This always returns text, so cast to bool on the other end to be certain
of the result.
Expand All @@ -80,9 +82,7 @@
{{- true_one(['entity_1','entity_2]') | bool -}}
#}
{# 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)
-%}
{%- if entity_list is list -%}
{{- entity_list | map('states')
| map('bool', null) | select('eq', True)
| list | count == 1 -}}
Expand All @@ -102,6 +102,8 @@
The number of entities are counted.
If the 2 counts are the same, True is returned, else False,
defaults to False.
homeassistant:
min_version: 2023.11.0
REMEMBER!!
This always returns text, so cast to bool on the other end to be certain
of the result.
Expand All @@ -112,9 +114,7 @@
{{- true_all(['entity_1','entity_2']) | bool -}}
#}
{# 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)
-%}
{%- if entity_list is list -%}
{{- entity_list | map('states')
| map('bool', True) | select('eq', True)
| list | count == entity_list | count -}}
Expand All @@ -133,6 +133,8 @@
Items that do not evaluate as bool will be defaulted to null/undefined.
If there is only one that matches, True is returned,
else False, defaults to False.
homeassistant:
min_version: 2023.11.0
REMEMBER!!
This always returns text, so cast to bool on the other end to be certain
of the result.
Expand All @@ -143,9 +145,7 @@
{{- false_one(['entity_1','entity_2']) | bool -}}
#}
{# 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)
-%}
{%- if entity_list is list -%}
{{- entity_list | map('states')
| map('bool', null) | select('eq', False)
| list | count == 1 -}}
Expand All @@ -165,6 +165,8 @@
The number of entities are counted.
If the 2 counts are the same, True is returned, else False,
defaults to False.
homeassistant:
min_version: 2023.11.0
REMEMBER!!
This always returns text, so cast to bool on the other end to be certain
of the result.
Expand All @@ -175,9 +177,7 @@
{{- false_all(['entity_1','entity_2']) | bool -}}
#}
{# 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)
-%}
{%- if entity_list is list -%}
{{- entity_list | map('states')
| map('bool', False) | select('eq', False)
| list | count == entity_list | count -}}
Expand Down

0 comments on commit d535fd6

Please sign in to comment.