You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found several inconsistencies handling None/null value. I list the issues here and I demonstrate them later.
None value, if alone in developers tools models, is shown as null
None value, if alone in developers tools models, is shown as type dict
default filter is not working with None/null value (the result is None/null)
int and float filters are converting the value to 0 (is that right?) but if you provide a default value it will be used
I hope to get better consistency as when I develop complex scripts these things are a huge loss of time, often more than the script itself. I think that a complete check of special values and how they're handled by jinja templates would be great.
Here the text to use in Developers tools -> Models:
{# I set value with a not existant attribute at the moment. Same to assign it with None #}
{% set value = state_attr("media_center.google_mansarda", "volume_level") %}
Value: {{ value }}
Value is None: {{ value == None }}
Default value: {{ value | default(0.6) }}
As float: {{ value | float }}
As float with default: {{ value | float(0.6) }}
As int: {{ value | int }}
As int with default: {{ value | int(0.6) }}
Here is the result:
To demonstrate point 1 and 2 use this:
{# I set value with a not existant attribute at the moment. Same to assign it with None #}
{% set value = state_attr("media_center.google_mansarda", "volume_level") %}
{{ value }}
And here is the result:
What version of Home Assistant Core has the issue?
core-2021.12.10
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
No response
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
I suspect there could be other inconsistencies that I've never came across other than that. I suggest a review of how that special values are handled, especially with default values so that we have a predictable result when scripting :)
That said, thank you for your work, I really LOVE it!
PS: I'm a programmer but Python is not in my skill set, otherwise I would have been happy to do it by myself.
The text was updated successfully, but these errors were encountered:
The problem
I've found several inconsistencies handling None/null value. I list the issues here and I demonstrate them later.
I hope to get better consistency as when I develop complex scripts these things are a huge loss of time, often more than the script itself. I think that a complete check of special values and how they're handled by jinja templates would be great.
Here the text to use in Developers tools -> Models:
Here is the result:
To demonstrate point 1 and 2 use this:
And here is the result:
What version of Home Assistant Core has the issue?
core-2021.12.10
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
No response
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
I suspect there could be other inconsistencies that I've never came across other than that. I suggest a review of how that special values are handled, especially with default values so that we have a predictable result when scripting :)
That said, thank you for your work, I really LOVE it!
PS: I'm a programmer but Python is not in my skill set, otherwise I would have been happy to do it by myself.
The text was updated successfully, but these errors were encountered: