notoriousbdg / Home-AssistantConfig

Apache License 2.0
180 stars 49 forks source link

template warnings under 2021.4.x #32

Open jonwaland opened 3 years ago

jonwaland commented 3 years ago

2021-04-09 13:17:00 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'mappingproxy object' has no attribute 'icon' when rendering '{%- for item in states.sensor if (.....

Warning is created in the update_battery_status_group_membersautomation

jonwaland commented 3 years ago

Proposed fix https://community.home-assistant.io/t/howto-create-battery-alert-without-creating-a-template-for-every-device/30576/947?u=walaj

tfili commented 3 years ago

@jonwaland That fix seems like it wouldn't be what you want. That fix says if icon isn't defined then it will never add the entity. Something like this would probably be better:

              {%- for item in states.sensor if (
                not is_state_attr(item.entity_id, 'hidden', true)
                and (
                  is_state_attr(item.entity_id, 'device_class', 'battery')
                  or (item.attributes.icon is defined and 'battery' in item.attributes.icon | lower)
                  or (item.entity_id | lower).endswith('_bat')
                  or (item.name | lower).endswith('_bat')
                  ) or (
                    (
                      'battery' in item.entity_id | lower
                      or 'battery' in item.name | lower
                    ) and (
                      item.attributes.icon is not defined
                    ) and (
                      not is_state_attr(item.entity_id, 'battery_alert_disabled', true)
                    ) and (
                      not is_state_attr(item.entity_id, 'restored', true)
                    )
                  )
                )
              -%}
                {{ item.entity_id }}{% if not loop.last %}, {% endif %}
              {%- endfor -%}
jonwaland commented 3 years ago

yup - my mistake - I meant it to be a qualifier for the check - but put it outside. thanks.

So how to get this added to the actual package for others?

tfili commented 3 years ago

It's up to @notoriousbdg. Do you want a PR or do you want to just make the fix.

tingox commented 2 years ago

pull request #33 fixes the warnings for me in Home Assistant 2021.11.3 - thanks!