Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/src/configs/jimpower/lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions demo/src/configs/teachingbirds/lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions gallery/src/data/traces/basic_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const basicTrace: DemoTrace = {
params: {
domain: "input_boolean",
service: "toggle",
service_data: {},
data: {},
target: {
entity_id: ["input_boolean.toggle_4"],
},
Expand Down Expand Up @@ -164,7 +164,7 @@ export const basicTrace: DemoTrace = {
params: {
domain: "input_boolean",
service: "toggle",
service_data: {},
data: {},
target: {
entity_id: ["input_boolean.toggle_2"],
},
Expand All @@ -182,7 +182,7 @@ export const basicTrace: DemoTrace = {
params: {
domain: "input_boolean",
service: "toggle",
service_data: {},
data: {},
target: {
entity_id: ["input_boolean.toggle_3"],
},
Expand All @@ -200,7 +200,7 @@ export const basicTrace: DemoTrace = {
params: {
domain: "input_boolean",
service: "toggle",
service_data: {},
data: {},
target: {
entity_id: ["input_boolean.toggle_4"],
},
Expand Down
2 changes: 1 addition & 1 deletion gallery/src/pages/lovelace/entities-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gallery/src/pages/lovelace/glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gallery/src/pages/lovelace/picture-elements-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/components/ha-service-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions src/data/lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
service_data?: Record<string, unknown>;
// "service_data" is kept to be backwards-compatible. New coding should be using "data" instead.
service_data?: Record<string, unknown>;

data?: Record<string, unknown>;
}

export interface NavigateActionConfig extends BaseActionConfig {
Expand Down
2 changes: 2 additions & 0 deletions src/panels/lovelace/cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
service_data?: Record<string, unknown>;
// "service_data" is kept to be backwards-compatible. New coding should be using "data" instead.
service_data?: Record<string, unknown>;

data?: Record<string, unknown>;
url?: string;
tap_action?: ActionConfig;
hold_action?: ActionConfig;
Expand Down
12 changes: 8 additions & 4 deletions src/panels/lovelace/common/compute-unused-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/common/handle-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const handleAction = async (
hass.callService(
domain,
service,
actionConfig.service_data,
actionConfig.data ?? actionConfig.service_data,
actionConfig.target
);
forwardHaptic("light");
Expand Down
22 changes: 13 additions & 9 deletions src/panels/lovelace/components/hui-action-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
);
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/panels/lovelace/editor/structs/action-struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())])),
Expand Down
2 changes: 1 addition & 1 deletion src/panels/lovelace/special-rows/hui-call-service-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,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": {
Expand Down