From 1ae771d2551b008dea9c201e257d63f6fe91d9f2 Mon Sep 17 00:00:00 2001 From: Jason <37859597+zachowj@users.noreply.github.com> Date: Fri, 16 Aug 2024 23:37:36 -0700 Subject: [PATCH] fix: Move entity_id from target field to data field --- src/nodes/action/ActionController.ts | 28 +++++++++++++++++++++++++++- src/nodes/action/locale.json | 3 ++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/nodes/action/ActionController.ts b/src/nodes/action/ActionController.ts index ebb2382989..28b463b179 100644 --- a/src/nodes/action/ActionController.ts +++ b/src/nodes/action/ActionController.ts @@ -22,6 +22,7 @@ export default class ActionController extends InputOutputController< > { #queue: QueueItem[] = []; #hasDeprecatedWarned = false; + #hasDeprecatedWarnedTargetEntityId = false; protected async onInput({ message, @@ -72,6 +73,31 @@ export default class ActionController extends InputOutputController< render, ); + // TODO: Remove in version 1.0 - Check if entity_id should be in the data field not the target field + if ( + parsedMessage.action?.value && + typeof target.entity_id === 'string' + ) { + const services = this.homeAssistant.websocket.getServices(); + const [domain, service] = parsedMessage.action?.value + .toLowerCase() + .split('.'); + + if ( + services[domain]?.[service]?.fields?.entity_id !== undefined && + !mergedData.entity_id + ) { + if (!this.#hasDeprecatedWarnedTargetEntityId) { + this.#hasDeprecatedWarnedTargetEntityId = true; + this.node.warn( + RED._('ha-action.error.entity_id_target_data'), + ); + } + mergedData.entity_id = target.entity_id; + target.entity_id = undefined; + } + } + const queueItem: QueueItem = { domain, service, @@ -301,7 +327,7 @@ export default class ActionController extends InputOutputController< ); this.status.setSuccess([ - 'ha-action.status.service_called', + 'ha-action.status.action_called', { domain, service }, ]); diff --git a/src/nodes/action/locale.json b/src/nodes/action/locale.json index d8a48f0eac..e483505dc9 100644 --- a/src/nodes/action/locale.json +++ b/src/nodes/action/locale.json @@ -2,6 +2,7 @@ "ha-action": { "error": { "domain_service_deprecated": "The domain and service input properties are deprecated and will be removed in version 1.0. Please use the action property instead.", + "entity_id_target_data": "Entity ID is required to be in the data property for this action. Please add the entity ID to the data property. This will stop working in version 1.0.", "invalid_action_format": "Invalid action format: __action__", "invalid_entity_id": "Invalid entity ID format", "invalid_json": "Invalid JSON: __json__", @@ -26,7 +27,7 @@ "targets": "Targets" }, "status": { - "service_called": "__domain__.__service__ called" + "action_called": "__domain__.__service__ called" } } }