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