Nerwyn/service-call-tile-feature

Selector too optimistic when using confirmation

jensrossbach opened this issue · 7 comments

Checklist:

  • I updated to the latest version available
  • I cleared the cache of my browser

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

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.

I tested the alpha version and it works as you described. Unfortunately it doesn't look very nice that the selector jumps forth and back in this case (even when setting "Update after action delay" to a low value).

Try the beta (4.1.0-beta.002 at time of writing). I've added some logic to propagate the confirmation failure and reset value logic up from the button to it's parent element, and it's now resetting almost immediately after cancelling the confirmation. This newer logic also seems to be working with spinboxes.

Unfortunately it looks the same with the beta.

Are you absolutely sure that it's loading the latest beta and not a cached version?

You are right, sorry. I installed the beta via the browser on my PC and cleared the cache here but actually tested it later on my phone via the companion app without explicitly clearing the cache there.

So now it seems to look fine, thanks!