immersive-home/app/lib/home_apis/hass_ws/templates/devices.j2
2024-05-06 12:42:45 +02:00

23 lines
1003 B
Django/Jinja

{% set devices = states | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list %}
{%- set ns = namespace(devices = [], entities = []) %}
{%- for device in devices %}
{%- set entities = device_entities(device) | list %}
{%- set ns.entities = [] %}
{%- if entities %}
{%- for entity in entities %}
{%- set ns.entities = ns.entities + [ {"id": entity, "name": state_attr(entity, "friendly_name")} ] %}
{%- endfor %}
{%- set ns.devices = ns.devices + [{"id": device, "name": device_attr(device, "name"), "entities": ns.entities } ] %}
{%- endif %}
{%- endfor %}
{%- set ns_group = namespace(entities = []) %}
{%- for state in states %}
{%- if device_id(state.entity_id) == None %}
{%- set ns_group.entities = ns_group.entities + [{"id": state.entity_id, "name": state.entity_id}] %}
{%- endif %}
{%- endfor %}
{%- set ns.devices = ns.devices + [ {"id": "other.other", "name": "Other", "entities": ns_group.entities } ] %}
{{ ns.devices }}