mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix overzealous loading of ha-service-control default values (#15741)
This commit is contained in:
parent
f193563649
commit
4d19e3ad63
@ -136,6 +136,7 @@ export class HaServiceControl extends LitElement {
|
|||||||
if (oldValue?.service !== this.value?.service) {
|
if (oldValue?.service !== this.value?.service) {
|
||||||
let updatedDefaultValue = false;
|
let updatedDefaultValue = false;
|
||||||
if (this._value && serviceData) {
|
if (this._value && serviceData) {
|
||||||
|
const loadDefaults = this.value && !("data" in this.value);
|
||||||
// Set mandatory bools without a default value to false
|
// Set mandatory bools without a default value to false
|
||||||
if (!this._value.data) {
|
if (!this._value.data) {
|
||||||
this._value.data = {};
|
this._value.data = {};
|
||||||
@ -152,6 +153,7 @@ export class HaServiceControl extends LitElement {
|
|||||||
this._value!.data![field.key] = false;
|
this._value!.data![field.key] = false;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
loadDefaults &&
|
||||||
field.selector &&
|
field.selector &&
|
||||||
field.default !== undefined &&
|
field.default !== undefined &&
|
||||||
this._value!.data![field.key] === undefined
|
this._value!.data![field.key] === undefined
|
||||||
@ -341,10 +343,10 @@ export class HaServiceControl extends LitElement {
|
|||||||
.selector=${dataField.selector}
|
.selector=${dataField.selector}
|
||||||
.key=${dataField.key}
|
.key=${dataField.key}
|
||||||
@value-changed=${this._serviceDataChanged}
|
@value-changed=${this._serviceDataChanged}
|
||||||
.value=${this._value?.data &&
|
.value=${this._value?.data
|
||||||
this._value.data[dataField.key] !== undefined
|
|
||||||
? this._value.data[dataField.key]
|
? this._value.data[dataField.key]
|
||||||
: dataField.default}
|
: undefined}
|
||||||
|
.placeholder=${dataField.default}
|
||||||
></ha-selector>
|
></ha-selector>
|
||||||
</ha-settings-row>`
|
</ha-settings-row>`
|
||||||
: "";
|
: "";
|
||||||
@ -362,7 +364,7 @@ export class HaServiceControl extends LitElement {
|
|||||||
this._value?.service,
|
this._value?.service,
|
||||||
this.hass.services
|
this.hass.services
|
||||||
)?.fields.find((field) => field.key === key)?.default;
|
)?.fields.find((field) => field.key === key)?.default;
|
||||||
if (defaultValue) {
|
if (defaultValue != null) {
|
||||||
data = {
|
data = {
|
||||||
...this._value?.data,
|
...this._value?.data,
|
||||||
[key]: defaultValue,
|
[key]: defaultValue,
|
||||||
|
@ -57,7 +57,9 @@ export class HuiActionEditor extends LitElement {
|
|||||||
private _serviceAction = memoizeOne(
|
private _serviceAction = memoizeOne(
|
||||||
(config: CallServiceActionConfig): ServiceAction => ({
|
(config: CallServiceActionConfig): ServiceAction => ({
|
||||||
service: this._service,
|
service: this._service,
|
||||||
data: config.data ?? config.service_data,
|
...(config.data || config.service_data
|
||||||
|
? { data: config.data ?? config.service_data }
|
||||||
|
: null),
|
||||||
target: config.target,
|
target: config.target,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -196,9 +198,12 @@ export class HuiActionEditor extends LitElement {
|
|||||||
const value = {
|
const value = {
|
||||||
...this.config!,
|
...this.config!,
|
||||||
service: ev.detail.value.service || "",
|
service: ev.detail.value.service || "",
|
||||||
data: ev.detail.value.data || {},
|
data: ev.detail.value.data,
|
||||||
target: ev.detail.value.target || {},
|
target: ev.detail.value.target || {},
|
||||||
};
|
};
|
||||||
|
if (!ev.detail.value.data) {
|
||||||
|
delete value.data;
|
||||||
|
}
|
||||||
// "service_data" is allowed for backwards compatibility but replaced with "data" on write
|
// "service_data" is allowed for backwards compatibility but replaced with "data" on write
|
||||||
if ("service_data" in value) {
|
if ("service_data" in value) {
|
||||||
delete value.service_data;
|
delete value.service_data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user