Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more controllability for !extends merging when it comes to lists #2879

Open
wrouesnel opened this issue Sep 12, 2024 · 0 comments
Open

Comments

@wrouesnel
Copy link

Describe the problem you have/What new integration you would like

When I have a package with a component in it that includes a list of actions - i.e. a binary sensor for a switch or something similar like so:

  - platform: gpio
    id: the_switch
    name: "Power Switch"
    disabled_by_default: true
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
    on_state:
      - light.toggle: mini_relay
      - light.toggle: led
    filters:
      - delayed_on_off: ${switch_delayed_on_off}

then if I want to extend it to add new functionality then the logical thing to is use the !extend command. However, the extend command currently works by only appending lists - so a change which is intended to modify control flow doesn't work - i.e. this:

  - id: !extend the_switch
    on_state:
      - if:
          condition: 
            lambda: 'return id(sw_interlock) != true;'
          then:
          - light.toggle: mini_relay
          - light.toggle: led
          else:
          - logger.log: "Physical switch locked out"
    filters:
      - delayed_on_off: ${switch_delayed_on_off}

results in this effective configuration:

  - platform: gpio
    id: the_switch
    name: "Power Switch"
    disabled_by_default: true
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
    on_state:
      - light.toggle: mini_relay
      - light.toggle: led
      - if:
          condition: 
            lambda: 'return id(sw_interlock) != true;'
          then:
          - light.toggle: mini_relay
          - light.toggle: led
          else:
          - logger.log: "Physical switch locked out"
    filters:
      - delayed_on_off: ${switch_delayed_on_off}

Note that the list has simple had the actions appended. I understand this is intended behavior and serves a sensible use case under most conditions.

What I would like to be able to do is something like this:

  - id: !extend the_switch
    on_state: !replace
      - if:
          condition: 
            lambda: 'return id(sw_interlock) != true;'
          then:
          - light.toggle: mini_relay
          - light.toggle: led
          else:
          - logger.log: "Physical switch locked out"
    filters:
      - delayed_on_off: ${switch_delayed_on_off}

And have it accomplish the original intent - replace rather then extend the on_state list of actions.

Please describe your use case for this integration and alternatives you've tried:
The use case is replacing control flow in existing packages where I am not simply extending the action lists.

The current alternative is to the use the !remove syntax and copy and paste the entire component into the derived file. This is fine, but it does limit the usefulness of the !extend syntax.

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant