Allow passing the current value to config flow input fields (#5603)

* Allow passing the current value to config flow input fields

* Fix lint errors

* Apply suggestions from code review

Co-Authored-By: Bram Kragten <mail@bramkragten.nl>

* Rename current_value to suggested_value to open up more use cases

* Update ha-form-integer.ts

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
On Freund 2020-05-01 11:36:51 +03:00 committed by GitHub
parent dfd9bf3c64
commit 1687d90d02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View File

@ -77,7 +77,12 @@ export class HaFormInteger extends LitElement implements HaFormElement {
}
private get _value() {
return this.data || this.schema.default || 0;
return (
this.data ||
this.schema.description?.suggested_value ||
this.schema.default ||
0
);
}
private _handleCheckboxChange(ev: Event) {

View File

@ -30,7 +30,7 @@ export interface HaFormBaseSchema {
default?: HaFormData;
required?: boolean;
optional?: boolean;
description?: { suffix?: string };
description?: { suffix?: string; suggested_value?: HaFormData };
}
export interface HaFormIntegerSchema extends HaFormBaseSchema {

View File

@ -122,7 +122,9 @@ class StepFlowForm extends LitElement {
const data = {};
this.step.data_schema.forEach((field) => {
if ("default" in field) {
if (field.description?.suggested_value) {
data[field.name] = field.description.suggested_value;
} else if ("default" in field) {
data[field.name] = field.default;
}
});