using the slugify example:
{{ "Hello World"|slugify(separator="_") }}
It receives a string and handles it. This, in my point of view, should do the same, receive a string and return true or false
using the slugify example:
{{ "Hello World"|slugify(separator="_") }}
It receives a string and handles it. This, in my point of view, should do the same, receive a string and return true or false
It should do all of them. The goal is to shorten syntax in all the use cases where ‘unknown’ and ‘unavailable’ need to be checked, which is selectors and if statements.
I’m good with that… so if its a string handles as a string, if its a dict it handles that dictionary and process accordingly.
Just pushed update for PR. It will now do state objects and strings. This means following works:
{{ is_nominal('sensor.test') }}
{{ is_nominal(states.sensor.test) }}
{% if 'sensor.test' is is_nominal %} ...
{% if states.sensor.test is is_nominal %} ...
{{ states.sensor.test is is_nominal }}
{{ states | select('is_nominal') | list }}
{{ states | selectattr('state', 'is_nominal') | list }}
{{ is_nominal(states.sensor.test.attributes.attr) }}
{{ is_nominal(state_attr('sensor.test', 'attr')) }}
{{ 'sensor.test' | is_nominal }}
{{ states.sensor.test | is_nominal }}
what also works is providing a list:
{{ is_nominal(['sensor.test1', 'states.sensor.test2']) }}
{{ is_nominal([states.sensor.test1, states.sensor.test2]) }}
{{ is_nominal([states.sensor.test1, 'states.sensor.test2']) }}
{{ ['sensor.test1', 'states.sensor.test2'] | is_nominal() }}
{{ [states.sensor.test1, states.sensor.test2] | is_nominal() }}
{{ [states.sensor.test1, 'states.sensor.test2'] | is_nominal() }}
What does not really work is:
{{ states | selectattr('attributes.attr', 'is_nominal') | list }}
If the attribute does not exist for an entity then it fails in rendering the template itself resulting in also those without the attribute being added to the list. Does not even get to the is_nominal function.
Yeah, that’s expected. You’d have to check if the attribute is defined before checking it’s value.
{{ states | selectattr('attributes.attr', 'defined') | selectattr('attributes.attr', 'is_nominal') | list }}
I’m looking at your code and I think you’re getting false positives and assuming it’s correct. I’ll comment on the PR
EDIT: nevermind, I must have been loooking at the first version of your PR…
Testing includes both positive and negative, so shouldn’t be. But please review and comment.
Yeah, I was looking… Not sure, but I refreshed the page and saw your current changes and made my comments.
This WTH is solved some time ago when the has_value
function/filter was introduced.