artem-sedykh / mini-climate-card

Minimalistic climate card for Home Assistant Lovelace UI
MIT License
281 stars 19 forks source link

current selection in selected_value list is not bold #72

Closed kannkann closed 2 years ago

kannkann commented 2 years ago

previously the current value was marked in bold in the selected_value list. that was quite useful. could that be restored? I use 4 buttons with lists in my card. Thank you for the great work.

ps.: could there be more examples? how do filters work? I have an attribute as following, but I am not sure how to populate the selection list automatically.

fan_modes:
  - auto
  - '1'
....
regevbr commented 2 years ago

Sure I already have a fix, will release it shortly. Can you please explain more in detail what it is you want to achieve?

regevbr commented 2 years ago

released in v2.0.2

kannkann commented 2 years ago

Thank you, it works.

Regarding the filter: Currently I use 4 buttons for fan speed, left-right swing mode, top-button swing mode, and climate mode. I was wondering if there is a way to populate the selection list using the climate attribute with an array of options. Current setting I am using:

  swing_mode:
    type: dropdown
    state:
      attribute: swing_mode
    source:
      '2':
        name: '2'
        order: 2
      '3':
        name: '3'
        order: 3
      '4':
        name: '4'
        order: 4
      auto:
        name: auto
        order: 0
      1_up:
        name: 1_up
        order: 1
      5_down:
        name: 5_down
        order: 5
      swing:
        name: swing
        order: 6
    change_action: >
      (selected, state, climate_entity) => this.call_service('climate',
      'set_swing_mode', { entity_id: climate_entity.entity_id, swing_mode:
      selected })

I was wondering if something like this works somehow?

swing_mode:
    type: dropdown
    state:
      attribute: swing_mode
    source:
      __filter: >
          """I do not understand this part."""
    change_action: >
      (selected, state, climate_entity) => this.call_service('climate',
      'set_swing_mode', { entity_id: climate_entity.entity_id, swing_mode:
      selected })
regevbr commented 2 years ago

Yes you can totally achieve that. The word 'filter' is not really good here, it should have been called 'map' I guess. if you look at the example given in the README:

    source:
      auto: Авто
      low: Слабый
      medium: Средний
      high: Сильный
      # for my implementation fan_modes_al is an array of available fan modes of the selected hvac mode
      __filter: >
        (source, state, entity) => entity.attributes
          .fan_modes_al.map(fan_mode => source.find(s => s.id === fan_mode))
          .filter(fan_mode => fan_mode)

You will notice that in the filter he actually replaces the source list with elements that only exist on the attributes of the entity. You can modify that example to generate the entire source list in that function based on the attributes of your entity. Just notice that the function should return an array of objects that have the id key set to them.

So if for example, your entity has an attribute called called swing_modes with various values, you can do the following:

swing_mode:
    type: dropdown
    state:
      attribute: swing_mode
    source:
      __filter: >
        (source, state, entity) => entity.attributes
          .swing_modes.map((swing_mode, ind) => {
              return {id: swing_mode, name: swing_mode, order: ind}
        })

And it will auto-populate the list with the values.

Hope that helps :-)

kannkann commented 2 years ago

Perfect, I think it worked without any problems. Thanks again.