custom-cards / flex-table-card

Highly Flexible Lovelace Card - arbitrary contents/columns/rows, regex matched, perfect to show appdaemon created content and anything breaking out of the entity_id + attributes concept
GNU General Public License v3.0
198 stars 23 forks source link

[Question] How to display list of dicts? #47

Open csoltenborn opened 3 years ago

csoltenborn commented 3 years ago

I'm trying to display information about outdated HACS components. For this, I have defined some sensors (basically following this approach) which provide the outdated repositories. Thus, with Development Tools/Template, the statement {{ (state_attr('binary_sensor.hacs_update_issues', 'status')).repositories }} results in the following output:

[{'name': 'FL550/dwd_weather', 'display_name': 'Deutscher Wetterdienst', 'installed_version': 'v1.2.1', 'available_version': 'v1.2.2'}, {'name': 'briis/weatherbit', 'display_name': 'Weatherbit Weather Forecast for Home Assistant', 'installed_version': 'v0.34', 'available_version': 'v0.34.1'}]

I'm then trying to use the following code for the UI part:

type: 'custom:auto-entities'
card:
  type: 'custom:flex-table-card'
  title: Pending HACS updates
  columns:
    - name: Component
      data: display_name
    - name: Current version
      data: installed_version
    - name: Latest version
      data: available_version
  sort:
    method: attribute
    attribute: display_name
filter:
  template: >
    {{ (state_attr('binary_sensor.hacs_update_issues', 'status')).repositories }}

However, no rows are shown. The same is true for the following template I tried.

    {%- for repository in (state_attr('binary_sensor.hacs_update_issues', 'status')).repositories -%}
      {{ repository}},
    {%- endfor -%} 

Is what I'm doing possible at all with flex-table-card? Thanks in advance...

patriciowallace commented 2 years ago

did you resolve it ?

lezioul commented 2 years ago

Well, i'm interested too.

daringer commented 2 years ago

this is currently not really possible, best would be something like that:

type: 'custom:flex-table-card'
  title: blub blub
  columns:
    - name: descent-into-object
      data: repositories.foo

already tried a naive approach, but this looks like this might be more challenging than expected...

EdLeckert commented 10 months ago

@csoltenborn Is this what you want? I realize this is a bit late, but...

PendingHACSUpdates

Created an input_boolean to simulate your example:

States

The Template view:

Template

The config:

type: custom:flex-table-card
title: Pending HACS Updates
sort_by:
  - display_name
entities:
  include: input_boolean.hacs_update_issues
columns:
  - name: Component
    data: status.repositories
    modify: x.display_name
    id: display_name
  - name: Current version
    data: status.repositories
    modify: x.installed_version
  - name: Latest version
    data: status.repositories
    modify: x.available_version