Allow passing the current value to config flow input fields#5603
Allow passing the current value to config flow input fields#5603bramkragten merged 5 commits intohome-assistant:devfrom
Conversation
|
This should also be added to all the |
Co-Authored-By: Bram Kragten <mail@bramkragten.nl>
|
Thanks @bramkragten.
Not sure what you mean. The |
|
I have to check how this all works, but you now do it in only one place. The device automations might also need this? And at least |
|
Looks like device automations now don't display the default at all, only the set value if it has it. I personally would like to remove the logic of setting the data based on But that might be out of scope for this PR. |
|
|
It is because |
|
This does not depend on a backend change right? |
|
No backend change required - this is completely backwards compatible. |
|
@bramkragten I think there might be a bug here that I missed because my backend was covering up for it - if the user changes nothing in the form and submits, the suggested value isn't used. My best suggestion on how to fix this is to end this._stepData = data;
return data;But I'm assuming there's a reason it's not there? Maybe we can set it only in case a suggested value was picked up? |
|
Something like: private get _stepDataProcessed() {
if (this._stepData !== undefined) {
return this._stepData;
}
const data = {};
var suggestion_used = false;
this.step.data_schema.forEach((field) => {
if (field.description?.suggested_value) {
data[field.name] = field.description.suggested_value;
suggestion_used = true;
} else if ("default" in field) {
data[field.name] = field.default;
}
});
if (suggestion_used) {
this._stepData = data;
}
return data;
} |
|
I think we can just set it, it only means the frontend is doing the backends work of setting defaults. |
|
OK, new PR here: #5688 |
Proposed change
This PR creates a mechanism for the backend to pass the current value of config flow fields. The existing way of doing this is to set the
defaultparameter in the schema, but that has the adverse effect of not being able to remove an optional value, since it will be populated with the default if left empty.After this PR is merged, the backend can pass the current value without setting a default. An example:
If the current value is not present, the default will still be used, so existing integrations would not be broken as a result of this change.
You can also mix and match the current value and the default - the dialog will show the current value, but if left empty, the default will be used.
Type of change
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: