daredoes / linked-lovelace-ui

Create cards that can be re-used, updated, and handle templated data.
MIT License
33 stars 3 forks source link

The context gets replicated after update #40

Open erkr opened 4 months ago

erkr commented 4 months ago

Checklist:

Release with the issue: 2.2.5 Last working release (if known):

Browser and Operating System: iOS Safari

Description of problem:

I create a collapsible card with sub cards. At the top level I defined a context. After update, the context gets copied to all sub card levels. That should NOT happen. I even have another card where this doesn't happen. 3 examples included below.

Javascript errors shown in the web inspector (if applicable):

Additional information:

The original ll_key card, as I originally created:

ll_key: test_card
ll_context:
  group: sensor.temperatures_koelkasten
  name: Temperatuur
type: custom:collapsable-cards
title_card:
  type: tile
  name: <%= context.name %>
  entity: <%= context.group %>
cards:
  - type: custom:auto-entities
    card:
      type: entities
    filter:
      template: >
        {% set ns=namespace(entries=[]) %}  {% set entities=state_attr('<%=
        context.group %>','entity_id') or [] %}  {%- for entity in entities -%}
          {%- set ns.entries=ns.entries+[{'entity': entity, }] -%}
        {%- endfor -%}   {{ ns.entries }}
    sort:
      method: none
  - type: custom:auto-entities
    card:
      type: history-graph
      hours_to_show: 48
    filter:
      template: >
        {% set ns=namespace(entries=[]) %}  {% set entities=state_attr('<%=
        context.group %>','entity_id') or [] %}  {%- for entity in entities -%}
          {%- set ns.entries=ns.entries+[{'entity': entity, }] -%}
        {%- endfor -%}   {{ ns.entries }}
    sort:
      method: none

The same card after update (contains copies of ll_context in the sub cards):

ll_key: test_card
ll_context:
  group: sensor.temperatures_koelkasten
  name: Temperatuur
type: custom:collapsable-cards
title_card:
  type: tile
  name: <%= context.name %>
  entity: <%= context.group %>
cards:
  - type: custom:auto-entities
    card:
      type: entities
      ll_context:
        group: sensor.temperatures_koelkasten
        name: Temperatuur
    filter:
      template: >
        {% set ns=namespace(entries=[]) %}  {% set entities=state_attr('<%=
        context.group %>','entity_id') or [] %}  {%- for entity in entities -%}
          {%- set ns.entries=ns.entries+[{'entity': entity, }] -%}
        {%- endfor -%}   {{ ns.entries }}
    sort:
      method: none
    ll_context:
      group: sensor.temperatures_koelkasten
      name: Temperatuur
  - type: custom:auto-entities
    card:
      type: history-graph
      hours_to_show: 48
      ll_context:
        group: sensor.temperatures_koelkasten
        name: Temperatuur
    filter:
      template: >
        {% set ns=namespace(entries=[]) %}  {% set entities=state_attr('<%=
        context.group %>','entity_id') or [] %}  {%- for entity in entities -%}
          {%- set ns.entries=ns.entries+[{'entity': entity, }] -%}
        {%- endfor -%}   {{ ns.entries }}
    sort:
      method: none
    ll_context:
      group: sensor.temperatures_koelkasten
      name: Temperatuur

The same card where ll_context doesn't replicate to all the lower card levels. The only difference is that I start with an entities card on top level:

ll_key: test_card
ll_context:
  group: sensor.temperatures_koelkasten
  name: Temperatuur
type: entities
entities:
  - type: custom:collapsable-cards
    title_card:
      type: tile
      name: <%= context.name %>
      entity: <%= context.group %>
    cards:
      - type: custom:auto-entities
        card:
          type: entities
        filter:
          template: >
            {% set ns=namespace(entries=[]) %}  {% set entities=state_attr('<%=
            context.group %>','entity_id') or [] %}  {%- for entity in entities
            -%}
              {%- set ns.entries=ns.entries+[{'entity': entity, }] -%}
            {%- endfor -%}   {{ ns.entries }}
        sort:
          method: none
      - type: custom:auto-entities
        card:
          type: history-graph
          hours_to_show: 48
        filter:
          template: >
            {% set ns=namespace(entries=[]) %}  {% set entities=state_attr('<%=
            context.group %>','entity_id') or [] %}  {%- for entity in entities
            -%}
              {%- set ns.entries=ns.entries+[{'entity': entity, }] -%}
            {%- endfor -%}   {{ ns.entries }}
        sort:
          method: none
erkr commented 4 months ago

@daredoes Update. The copying of the ll_context is not unique for the collapsible card. Happens with auto-entities as well: image

This seems really a show stopper. The card marked with ll_key should not change, but this does happen depending the card type.

erkr commented 4 months ago

@daredoes please share your thoughts about this issue:

Best Eric

daredoes commented 4 months ago

@erkr Definitely a bug. Just started a new job this week. I'll try to find some time for the fix this weekend. Should be a pretty quick one. Examples to come as well. Appreciate the patience.

erkr commented 4 months ago

Great to hear that, and success with the new job, that will be a challenging period 🍀

nomonkeynodeal commented 4 months ago

I am having the same issue, weirdly only with one card.

erkr commented 4 months ago

I am having the same issue, weirdly only with one card.

I noticed cards that have entities as root are not effected

erkr commented 4 months ago

@daredoes

Hi Daniel, I have decided to use the decluttering card for my new dashboards.

Performance wise, your solution looks better.

I will keep the linked Lovelace evaluation card on my system for a while. So I can assist you to verify this issue.

Succes with your new job Eric

erkr commented 2 months ago

Hé @daredoes Are you still planning to fix the issue? If not I will remove my dashboard that I preserved for testing

daredoes commented 2 months ago

@erkr my bad on ignoring this for awhile. got swept up in the new job and some life stuff. Just took a stab at fixing the problem. Wrote a test that I think confirms the issue.

I need to do a bit more serious testing. Still, back up your system and then gives this a go.

erkr commented 2 months ago

New jobs can be challenging the first months. Will give it a try in the coming days

nomonkeynodeal commented 2 months ago

I just did a quick test and it seems to work. Although I did have to delete ll_context from a key because it was overwriting the context in the template. Thanks for working on this!

erkr commented 2 months ago

I did a quick check and it is not solved. A key card was still extended with additional context blocks