mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-15 05:16:34 +00:00
Change service_data to just data (#12628)
This commit is contained in:
parent
536ea822b3
commit
e3d394eb32
@ -194,7 +194,7 @@ export const demoLovelaceJimpower: DemoConfig["lovelace"] = () => ({
|
|||||||
type: "state-icon",
|
type: "state-icon",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "group.downstairs_lights",
|
entity_id: "group.downstairs_lights",
|
||||||
},
|
},
|
||||||
service: "homeassistant.toggle",
|
service: "homeassistant.toggle",
|
||||||
|
@ -377,7 +377,7 @@ export const demoLovelaceTeachingbirds: DemoConfig["lovelace"] = () => ({
|
|||||||
name: "AC bed",
|
name: "AC bed",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "script.air_cleaner_quiet",
|
entity_id: "script.air_cleaner_quiet",
|
||||||
},
|
},
|
||||||
service: "script.turn_on",
|
service: "script.turn_on",
|
||||||
@ -390,7 +390,7 @@ export const demoLovelaceTeachingbirds: DemoConfig["lovelace"] = () => ({
|
|||||||
name: "AC bed",
|
name: "AC bed",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "script.air_cleaner_auto",
|
entity_id: "script.air_cleaner_auto",
|
||||||
},
|
},
|
||||||
service: "script.turn_on",
|
service: "script.turn_on",
|
||||||
@ -403,7 +403,7 @@ export const demoLovelaceTeachingbirds: DemoConfig["lovelace"] = () => ({
|
|||||||
name: "AC bed",
|
name: "AC bed",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "script.air_cleaner_turbo",
|
entity_id: "script.air_cleaner_turbo",
|
||||||
},
|
},
|
||||||
service: "script.turn_on",
|
service: "script.turn_on",
|
||||||
@ -416,7 +416,7 @@ export const demoLovelaceTeachingbirds: DemoConfig["lovelace"] = () => ({
|
|||||||
name: "AC",
|
name: "AC",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "script.ac_off",
|
entity_id: "script.ac_off",
|
||||||
},
|
},
|
||||||
service: "script.turn_on",
|
service: "script.turn_on",
|
||||||
@ -429,7 +429,7 @@ export const demoLovelaceTeachingbirds: DemoConfig["lovelace"] = () => ({
|
|||||||
name: "AC",
|
name: "AC",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "script.ac_on",
|
entity_id: "script.ac_on",
|
||||||
},
|
},
|
||||||
service: "script.turn_on",
|
service: "script.turn_on",
|
||||||
@ -629,7 +629,7 @@ export const demoLovelaceTeachingbirds: DemoConfig["lovelace"] = () => ({
|
|||||||
entity: "scene.morning_lights",
|
entity: "scene.morning_lights",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "scene.morning_lights",
|
entity_id: "scene.morning_lights",
|
||||||
},
|
},
|
||||||
service: "scene.turn_on",
|
service: "scene.turn_on",
|
||||||
@ -641,7 +641,7 @@ export const demoLovelaceTeachingbirds: DemoConfig["lovelace"] = () => ({
|
|||||||
entity: "scene.movie_time",
|
entity: "scene.movie_time",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "scene.movie_time",
|
entity_id: "scene.movie_time",
|
||||||
},
|
},
|
||||||
service: "scene.turn_on",
|
service: "scene.turn_on",
|
||||||
@ -702,7 +702,7 @@ export const demoLovelaceTeachingbirds: DemoConfig["lovelace"] = () => ({
|
|||||||
entity: "light.downstairs_lights",
|
entity: "light.downstairs_lights",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "light.downstairs_lights",
|
entity_id: "light.downstairs_lights",
|
||||||
},
|
},
|
||||||
service: "light.toggle",
|
service: "light.toggle",
|
||||||
@ -714,7 +714,7 @@ export const demoLovelaceTeachingbirds: DemoConfig["lovelace"] = () => ({
|
|||||||
entity: "light.upstairs_lights",
|
entity: "light.upstairs_lights",
|
||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service_data: {
|
data: {
|
||||||
entity_id: "light.upstairs_lights",
|
entity_id: "light.upstairs_lights",
|
||||||
},
|
},
|
||||||
service: "light.toggle",
|
service: "light.toggle",
|
||||||
|
@ -119,7 +119,7 @@ export const basicTrace: DemoTrace = {
|
|||||||
params: {
|
params: {
|
||||||
domain: "input_boolean",
|
domain: "input_boolean",
|
||||||
service: "toggle",
|
service: "toggle",
|
||||||
service_data: {},
|
data: {},
|
||||||
target: {
|
target: {
|
||||||
entity_id: ["input_boolean.toggle_4"],
|
entity_id: ["input_boolean.toggle_4"],
|
||||||
},
|
},
|
||||||
@ -164,7 +164,7 @@ export const basicTrace: DemoTrace = {
|
|||||||
params: {
|
params: {
|
||||||
domain: "input_boolean",
|
domain: "input_boolean",
|
||||||
service: "toggle",
|
service: "toggle",
|
||||||
service_data: {},
|
data: {},
|
||||||
target: {
|
target: {
|
||||||
entity_id: ["input_boolean.toggle_2"],
|
entity_id: ["input_boolean.toggle_2"],
|
||||||
},
|
},
|
||||||
@ -182,7 +182,7 @@ export const basicTrace: DemoTrace = {
|
|||||||
params: {
|
params: {
|
||||||
domain: "input_boolean",
|
domain: "input_boolean",
|
||||||
service: "toggle",
|
service: "toggle",
|
||||||
service_data: {},
|
data: {},
|
||||||
target: {
|
target: {
|
||||||
entity_id: ["input_boolean.toggle_3"],
|
entity_id: ["input_boolean.toggle_3"],
|
||||||
},
|
},
|
||||||
@ -200,7 +200,7 @@ export const basicTrace: DemoTrace = {
|
|||||||
params: {
|
params: {
|
||||||
domain: "input_boolean",
|
domain: "input_boolean",
|
||||||
service: "toggle",
|
service: "toggle",
|
||||||
service_data: {},
|
data: {},
|
||||||
target: {
|
target: {
|
||||||
entity_id: ["input_boolean.toggle_4"],
|
entity_id: ["input_boolean.toggle_4"],
|
||||||
},
|
},
|
||||||
|
@ -249,7 +249,7 @@ const CONFIGS = [
|
|||||||
name: Bed light
|
name: Bed light
|
||||||
action_name: Toggle light
|
action_name: Toggle light
|
||||||
service: light.toggle
|
service: light.toggle
|
||||||
service_data:
|
data:
|
||||||
entity_id: light.bed_light
|
entity_id: light.bed_light
|
||||||
- type: section
|
- type: section
|
||||||
label: Links
|
label: Links
|
||||||
|
@ -199,7 +199,7 @@ const CONFIGS = [
|
|||||||
tap_action:
|
tap_action:
|
||||||
action: call-service
|
action: call-service
|
||||||
service: light.turn_on
|
service: light.turn_on
|
||||||
service_data:
|
data:
|
||||||
entity_id: light.ceiling_lights
|
entity_id: light.ceiling_lights
|
||||||
- entity: sun.sun
|
- entity: sun.sun
|
||||||
name: Regular
|
name: Regular
|
||||||
|
@ -40,7 +40,7 @@ const CONFIGS = [
|
|||||||
left: 90%
|
left: 90%
|
||||||
padding: 0px
|
padding: 0px
|
||||||
service: light.turn_off
|
service: light.turn_off
|
||||||
service_data:
|
data:
|
||||||
entity_id: group.all_lights
|
entity_id: group.all_lights
|
||||||
- type: icon
|
- type: icon
|
||||||
icon: mdi:cctv
|
icon: mdi:cctv
|
||||||
@ -88,7 +88,7 @@ const CONFIGS = [
|
|||||||
left: 90%
|
left: 90%
|
||||||
padding: 0px
|
padding: 0px
|
||||||
service: light.turn_off
|
service: light.turn_off
|
||||||
service_data:
|
data:
|
||||||
entity_id: group.all_lights
|
entity_id: group.all_lights
|
||||||
- type: icon
|
- type: icon
|
||||||
icon: mdi:cctv
|
icon: mdi:cctv
|
||||||
|
@ -287,9 +287,7 @@ export class HaServiceControl extends LitElement {
|
|||||||
${shouldRenderServiceDataYaml
|
${shouldRenderServiceDataYaml
|
||||||
? html`<ha-yaml-editor
|
? html`<ha-yaml-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize("ui.components.service-control.data")}
|
||||||
"ui.components.service-control.service_data"
|
|
||||||
)}
|
|
||||||
.name=${"data"}
|
.name=${"data"}
|
||||||
.defaultValue=${this._value?.data}
|
.defaultValue=${this._value?.data}
|
||||||
@value-changed=${this._dataChanged}
|
@value-changed=${this._dataChanged}
|
||||||
|
@ -131,9 +131,9 @@ export interface CallServiceActionConfig extends BaseActionConfig {
|
|||||||
action: "call-service";
|
action: "call-service";
|
||||||
service: string;
|
service: string;
|
||||||
target?: HassServiceTarget;
|
target?: HassServiceTarget;
|
||||||
service_data?: {
|
// "service_data" is kept for backwards compatibility. Replaced by "data".
|
||||||
[key: string]: any;
|
service_data?: Record<string, unknown>;
|
||||||
};
|
data?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NavigateActionConfig extends BaseActionConfig {
|
export interface NavigateActionConfig extends BaseActionConfig {
|
||||||
|
@ -54,7 +54,9 @@ export interface EntitiesCardEntityConfig extends EntityConfig {
|
|||||||
| "brightness";
|
| "brightness";
|
||||||
action_name?: string;
|
action_name?: string;
|
||||||
service?: string;
|
service?: string;
|
||||||
|
// "service_data" is kept for backwards compatibility. Replaced by "data".
|
||||||
service_data?: Record<string, unknown>;
|
service_data?: Record<string, unknown>;
|
||||||
|
data?: Record<string, unknown>;
|
||||||
url?: string;
|
url?: string;
|
||||||
tap_action?: ActionConfig;
|
tap_action?: ActionConfig;
|
||||||
hold_action?: ActionConfig;
|
hold_action?: ActionConfig;
|
||||||
|
@ -6,16 +6,20 @@ export const EXCLUDED_DOMAINS = ["zone", "persistent_notification"];
|
|||||||
const addFromAction = (entities: Set<string>, actionConfig: ActionConfig) => {
|
const addFromAction = (entities: Set<string>, actionConfig: ActionConfig) => {
|
||||||
if (
|
if (
|
||||||
actionConfig.action !== "call-service" ||
|
actionConfig.action !== "call-service" ||
|
||||||
!actionConfig.service_data ||
|
(!actionConfig.target?.entity_id &&
|
||||||
!actionConfig.service_data.entity_id
|
!actionConfig.service_data?.entity_id &&
|
||||||
|
!actionConfig.data?.entity_id)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let entityIds = actionConfig.service_data.entity_id;
|
let entityIds =
|
||||||
|
actionConfig.service_data?.entity_id ??
|
||||||
|
actionConfig.data?.entity_id ??
|
||||||
|
actionConfig.target?.entity_id;
|
||||||
if (!Array.isArray(entityIds)) {
|
if (!Array.isArray(entityIds)) {
|
||||||
entityIds = [entityIds];
|
entityIds = [entityIds];
|
||||||
}
|
}
|
||||||
for (const entityId of entityIds) {
|
for (const entityId of entityIds as Array<string>) {
|
||||||
entities.add(entityId);
|
entities.add(entityId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -148,7 +148,7 @@ export const handleAction = async (
|
|||||||
hass.callService(
|
hass.callService(
|
||||||
domain,
|
domain,
|
||||||
service,
|
service,
|
||||||
actionConfig.service_data,
|
actionConfig.data ?? actionConfig.service_data,
|
||||||
actionConfig.target
|
actionConfig.target
|
||||||
);
|
);
|
||||||
forwardHaptic("light");
|
forwardHaptic("light");
|
||||||
|
@ -45,7 +45,7 @@ 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.service_data,
|
data: config.data ?? config.service_data,
|
||||||
target: config.target,
|
target: config.target,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -179,14 +179,18 @@ export class HuiActionEditor extends LitElement {
|
|||||||
|
|
||||||
private _serviceValueChanged(ev: CustomEvent) {
|
private _serviceValueChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
fireEvent(this, "value-changed", {
|
const value = {
|
||||||
value: {
|
...this.config!,
|
||||||
...this.config!,
|
service: ev.detail.value.service || "",
|
||||||
service: ev.detail.value.service || "",
|
data: ev.detail.value.data || {},
|
||||||
service_data: ev.detail.value.data || {},
|
target: ev.detail.value.target || {},
|
||||||
target: ev.detail.value.target || {},
|
};
|
||||||
},
|
// "service_data" is allowed for backwards compatibility but replaced with "data" on write
|
||||||
});
|
if ("service_data" in value) {
|
||||||
|
delete value.service_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
fireEvent(this, "value-changed", { value });
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
|
@ -76,7 +76,9 @@ const callServiceEntitiesRowConfigStruct = object({
|
|||||||
service: string(),
|
service: string(),
|
||||||
icon: optional(string()),
|
icon: optional(string()),
|
||||||
action_name: optional(string()),
|
action_name: optional(string()),
|
||||||
|
// "service_data" is kept for backwards compatibility. Replaced by "data".
|
||||||
service_data: optional(any()),
|
service_data: optional(any()),
|
||||||
|
data: optional(any()),
|
||||||
});
|
});
|
||||||
|
|
||||||
const conditionalEntitiesRowConfigStruct = object({
|
const conditionalEntitiesRowConfigStruct = object({
|
||||||
|
@ -32,6 +32,7 @@ const actionConfigStructService = object({
|
|||||||
action: literal("call-service"),
|
action: literal("call-service"),
|
||||||
service: string(),
|
service: string(),
|
||||||
service_data: optional(object()),
|
service_data: optional(object()),
|
||||||
|
data: optional(object()),
|
||||||
target: optional(
|
target: optional(
|
||||||
object({
|
object({
|
||||||
entity_id: optional(union([string(), array(string())])),
|
entity_id: optional(union([string(), array(string())])),
|
||||||
|
@ -23,7 +23,7 @@ export class HuiCallServiceRow extends HuiButtonRow {
|
|||||||
tap_action: {
|
tap_action: {
|
||||||
action: "call-service",
|
action: "call-service",
|
||||||
service: callServiceConfig.service,
|
service: callServiceConfig.service,
|
||||||
service_data: callServiceConfig.service_data,
|
data: callServiceConfig.service_data,
|
||||||
},
|
},
|
||||||
...callServiceConfig,
|
...callServiceConfig,
|
||||||
type: "button",
|
type: "button",
|
||||||
|
@ -521,7 +521,7 @@
|
|||||||
"required": "This field is required",
|
"required": "This field is required",
|
||||||
"target": "Targets",
|
"target": "Targets",
|
||||||
"target_description": "What should this service use as targeted areas, devices or entities.",
|
"target_description": "What should this service use as targeted areas, devices or entities.",
|
||||||
"service_data": "Service data",
|
"data": "Service data",
|
||||||
"integration_doc": "Integration documentation"
|
"integration_doc": "Integration documentation"
|
||||||
},
|
},
|
||||||
"related-items": {
|
"related-items": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user