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 default values for script fields in more-info dialog #20747

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

paolapersico1
Copy link

@paolapersico1 paolapersico1 commented May 6, 2024

Proposed change

Previously, the more-info dialog for script entities didn't show the user-defined default values for the script fields, this PR fixes this.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

alias: TestScript
sequence:
  - if:
      - condition: template
        value_template: "{{ testfield == \"decrement\" }}"
    then:
      - service: counter.decrement
        metadata: {}
        data: {}
        target:
          entity_id: counter.helper
    else:
      - service: counter.increment
        target:
          entity_id:
            - counter.helper
        data: {}
mode: single
fields:
  testfield:
    selector:
      select:
        options:
          - increment
          - decrement
    name: testfield
    default: increment
    required: true
icon: mdi:account

counter:
  helper:
    initial: 0
    step: 1

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

home-assistant[bot]

This comment was marked as outdated.

@home-assistant home-assistant bot marked this pull request as draft May 6, 2024 18:54
@home-assistant

This comment was marked as outdated.

this._scriptData = { service: newState.entity_id, data: {} };
const fields =
this.hass.services.script[computeObjectId(newState.entity_id)]?.fields;
const defaultValues = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use computeInitialHaFormData here.

@paolapersico1 paolapersico1 marked this pull request as draft May 8, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script field defaults are not used in frontend
2 participants