diff --git a/demo/src/configs/jimpower/lovelace.ts b/demo/src/configs/jimpower/lovelace.ts index 3f9ba918cb..934dfa7d10 100644 --- a/demo/src/configs/jimpower/lovelace.ts +++ b/demo/src/configs/jimpower/lovelace.ts @@ -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", diff --git a/demo/src/configs/teachingbirds/lovelace.ts b/demo/src/configs/teachingbirds/lovelace.ts index 9fbf612023..1ff4ff8807 100644 --- a/demo/src/configs/teachingbirds/lovelace.ts +++ b/demo/src/configs/teachingbirds/lovelace.ts @@ -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", diff --git a/gallery/src/data/traces/basic_trace.ts b/gallery/src/data/traces/basic_trace.ts index 6345b4f845..8fbd720e12 100644 --- a/gallery/src/data/traces/basic_trace.ts +++ b/gallery/src/data/traces/basic_trace.ts @@ -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"], }, diff --git a/gallery/src/pages/lovelace/entities-card.ts b/gallery/src/pages/lovelace/entities-card.ts index ce13f327b5..a4fc76a510 100644 --- a/gallery/src/pages/lovelace/entities-card.ts +++ b/gallery/src/pages/lovelace/entities-card.ts @@ -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 diff --git a/gallery/src/pages/lovelace/glance-card.ts b/gallery/src/pages/lovelace/glance-card.ts index 1e4d0755df..14941aaa4e 100644 --- a/gallery/src/pages/lovelace/glance-card.ts +++ b/gallery/src/pages/lovelace/glance-card.ts @@ -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 diff --git a/gallery/src/pages/lovelace/picture-elements-card.ts b/gallery/src/pages/lovelace/picture-elements-card.ts index f1f5941157..588d6be9bf 100644 --- a/gallery/src/pages/lovelace/picture-elements-card.ts +++ b/gallery/src/pages/lovelace/picture-elements-card.ts @@ -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 diff --git a/src/components/ha-service-control.ts b/src/components/ha-service-control.ts index 966052e4a6..54cca6a765 100644 --- a/src/components/ha-service-control.ts +++ b/src/components/ha-service-control.ts @@ -287,9 +287,7 @@ export class HaServiceControl extends LitElement { ${shouldRenderServiceDataYaml ? html`; + data?: Record; } export interface NavigateActionConfig extends BaseActionConfig { diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index f596046e63..e6189150e1 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -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; + data?: Record; url?: string; tap_action?: ActionConfig; hold_action?: ActionConfig; diff --git a/src/panels/lovelace/common/compute-unused-entities.ts b/src/panels/lovelace/common/compute-unused-entities.ts index a675923541..2408aac2ea 100755 --- a/src/panels/lovelace/common/compute-unused-entities.ts +++ b/src/panels/lovelace/common/compute-unused-entities.ts @@ -6,16 +6,20 @@ export const EXCLUDED_DOMAINS = ["zone", "persistent_notification"]; const addFromAction = (entities: Set, 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) { entities.add(entityId); } }; diff --git a/src/panels/lovelace/common/handle-action.ts b/src/panels/lovelace/common/handle-action.ts index 7bdbea4f49..ef489d49ca 100644 --- a/src/panels/lovelace/common/handle-action.ts +++ b/src/panels/lovelace/common/handle-action.ts @@ -148,7 +148,7 @@ export const handleAction = async ( hass.callService( domain, service, - actionConfig.service_data, + actionConfig.data ?? actionConfig.service_data, actionConfig.target ); forwardHaptic("light"); diff --git a/src/panels/lovelace/components/hui-action-editor.ts b/src/panels/lovelace/components/hui-action-editor.ts index 3ec925e58f..0874c7e3b8 100644 --- a/src/panels/lovelace/components/hui-action-editor.ts +++ b/src/panels/lovelace/components/hui-action-editor.ts @@ -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 { diff --git a/src/panels/lovelace/editor/config-elements/hui-entities-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-entities-card-editor.ts index 536eede67c..78b18d7230 100644 --- a/src/panels/lovelace/editor/config-elements/hui-entities-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-entities-card-editor.ts @@ -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({ diff --git a/src/panels/lovelace/editor/structs/action-struct.ts b/src/panels/lovelace/editor/structs/action-struct.ts index cee149e6d2..ef7a479bb2 100644 --- a/src/panels/lovelace/editor/structs/action-struct.ts +++ b/src/panels/lovelace/editor/structs/action-struct.ts @@ -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())])), diff --git a/src/panels/lovelace/special-rows/hui-call-service-row.ts b/src/panels/lovelace/special-rows/hui-call-service-row.ts index 5f461d5180..249debf095 100644 --- a/src/panels/lovelace/special-rows/hui-call-service-row.ts +++ b/src/panels/lovelace/special-rows/hui-call-service-row.ts @@ -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", diff --git a/src/translations/en.json b/src/translations/en.json index 41d242cbc1..d1a1d44f08 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -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": {