From 8dd947f140aa21cbd545d5064bcdd38698c85d11 Mon Sep 17 00:00:00 2001 From: jason <37859597+zachowj@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:13:50 -0700 Subject: [PATCH] feat(action): Add option to block input overrides in action nodes Existing nodes will retain input overrides disabled, while newly created nodes will have it enabled by default. Closes #1489 --- src/nodes/action/editor.html | 13 ++++++++++--- src/nodes/action/editor/index.ts | 2 ++ src/nodes/action/index.ts | 5 +++++ src/nodes/action/locale.json | 1 + src/nodes/action/migrations.ts | 12 ++++++++++++ test/migrations/action.test.ts | 22 +++++++++++++++++++++- 6 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/nodes/action/editor.html b/src/nodes/action/editor.html index c39e290edc..773a659254 100644 --- a/src/nodes/action/editor.html +++ b/src/nodes/action/editor.html @@ -72,10 +72,17 @@
+ +
+ +
+   + for="node-input-blockInputOverrides" + data-i18n="ha-action.label.block_input_overrides" + > +
diff --git a/src/nodes/action/editor/index.ts b/src/nodes/action/editor/index.ts index 4caf548fce..fee3086bf3 100644 --- a/src/nodes/action/editor/index.ts +++ b/src/nodes/action/editor/index.ts @@ -34,6 +34,7 @@ interface ActionEditorNodeProperties extends EditorNodeProperties { mustacheAltTags: boolean; queue: string; outputProperties: OutputProperty[]; + blockInputOverrides: boolean; // deprecated domain?: string; @@ -84,6 +85,7 @@ const ActionEditor: EditorNodeDef = { validate: haOutputs.validate, }, queue: { value: 'none' }, + blockInputOverrides: { value: true }, // deprecated domain: { value: '' }, diff --git a/src/nodes/action/index.ts b/src/nodes/action/index.ts index 10cd2a2a9a..98920cde05 100644 --- a/src/nodes/action/index.ts +++ b/src/nodes/action/index.ts @@ -35,6 +35,8 @@ export interface ActionNodeProperties extends BaseNodeProperties { mustacheAltTags: boolean; queue: Queue; outputProperties: OutputProperty[]; + blockInputOverrides: boolean; + // TODO: Remove in version 1.0 domain?: string; service?: string; @@ -121,6 +123,9 @@ export default function actionNode( schema: inputSchema, transform: transformInput, }); + if (this.config.blockInputOverrides) { + inputService.disableInputOverrides(); + } const controllerDeps = createControllerDependencies(this, homeAssistant); const controller = new ActionController({ diff --git a/src/nodes/action/locale.json b/src/nodes/action/locale.json index e483505dc9..bbb432b541 100644 --- a/src/nodes/action/locale.json +++ b/src/nodes/action/locale.json @@ -11,6 +11,7 @@ "label": { "action": "Action", "alternate_tags": "Use alternate template tags for the data field", + "block_input_overrides": "Block input overrides", "data": "Data", "load_example_data": "Load example data", "merge_context": "Merge context", diff --git a/src/nodes/action/migrations.ts b/src/nodes/action/migrations.ts index 7e8647ea98..56ea4c603a 100644 --- a/src/nodes/action/migrations.ts +++ b/src/nodes/action/migrations.ts @@ -122,6 +122,18 @@ export default [ newSchema.action = `${schema.domain}.${schema.service}`; } + return newSchema; + }, + }, + { + version: 7, + up: (schema: any) => { + const newSchema = { + ...schema, + version: 7, + blockInputOverrides: false, + }; + return newSchema; }, }, diff --git a/test/migrations/action.test.ts b/test/migrations/action.test.ts index 803e3e156a..ff463f235e 100644 --- a/test/migrations/action.test.ts +++ b/test/migrations/action.test.ts @@ -85,6 +85,12 @@ const VERSION_6 = { action: 'service_domain.service_action', }; +const VERSION_7 = { + ...VERSION_6, + version: 7, + blockInputOverrides: false, +}; + describe('Migrations - Call Service Node', function () { describe('Version 0', function () { it('should add version 0 to schema when no version is defined', function () { @@ -284,8 +290,22 @@ describe('Migrations - Call Service Node', function () { }); }); + describe('Version 7', function () { + let migrate: Migration | undefined; + + beforeAll(function () { + migrate = migrations.find((m) => m.version === 7); + }); + + it('should update version 6 to version 7', function () { + const migratedSchema = migrate?.up(VERSION_6); + + expect(migratedSchema).toEqual(VERSION_7); + }); + }); + it('should update an undefined version to current version', function () { const migratedSchema = migrate(VERSION_UNDEFINED); - expect(migratedSchema).toEqual(VERSION_6); + expect(migratedSchema).toEqual(VERSION_7); }); });