Nerwyn / service-call-tile-feature

Home Assistant custom features for tile cards and more. Call any action using buttons, sliders, selectors, and spinboxes
Apache License 2.0
87 stars 3 forks source link

Selector too optimistic when using confirmation #53

Open jensrossbach opened 4 days ago

jensrossbach commented 4 days ago

Checklist:

Release with the issue: 4.0.10

Last working release (if known): n/a

Browser and Operating System: Home Assistant companion app on iOS 18

Description of problem: I have configured a tile card with a custom feature. The custom feature is a selector with two options to turn on and off a light. The 'off' option additionally has a confirmation. When the light is on and I press on the 'off' option, the confirmation dialog is shown (as expected) but in the same moment, the selector switches to the 'off' option. When I then cancel the confirmation dialog, the selector is on the 'off' option although the light is still on.

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

Your Full Card Config

type: tile
entity: light.my_light
icon_tap_action:
  action: more-info
features:
  - type: custom:service-call
    entries:
      - type: selector
        entity_id: light.my_light
        options:
          - entity_id: light.my_light
            option: 'on'
            tap_action:
              action: perform-action
              perform_action: light.turn_on
              data: {}
              target:
                entity_id: light.my_light
            icon: mdi:lightbulb-on
          - entity_id: light.my_light
            option: 'off'
            tap_action:
              action: perform-action
              perform_action: light.turn_off
              data: {}
              target:
                entity_id: light.my_light
              confirmation:
                text: Really turn off?
            icon: mdi:power

Additional information: n/a

Nerwyn commented 16 hours ago

Good catch. The logic for handling confirmations and changing the current selector option are separate and there isn't a good way to prevent the selector from not changing on option click, but I can mitigate it.

I've modified the selector logic to better change it's value on click, to modify the option classes after render (which seems to work more consistently than on render), and to always request a render update after the value from hass delay timer expires (which seems to reset it to it's old value consistently). I've also added Update after action delay time as an option in the selector UI.

Can you try the 4.1.0 alpha? I think I've mostly mitigated the issue so that if the confirmation is not selected, it'll revert to it's old value by retrieving it from the hass object after 1000ms (default) or whatever the user sets for the selector.