Skip to content

Commit

Permalink
feat(action): Add option to block input overrides in action nodes
Browse files Browse the repository at this point in the history
Existing nodes will retain input overrides disabled, while newly created nodes will have it enabled by default.

Closes #1489
  • Loading branch information
zachowj committed Sep 9, 2024
1 parent 67e69f5 commit 8dd947f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/nodes/action/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@

<div class="form-row checkbox-option">
<input type="checkbox" id="node-input-debugenabled" />
<label for="node-input-debugenabled" data-i18n="ha-action.label.show_debug">
</label>
</div>

<div class="form-row checkbox-option">
<input type="checkbox" id="node-input-blockInputOverrides" />&nbsp;
<label
for="node-input-debugenabled"
data-i18n="ha-action.label.show_debug"
></label>
for="node-input-blockInputOverrides"
data-i18n="ha-action.label.block_input_overrides"
>
</label>
</div>

<div id="service-data-desc" class="form-row">
Expand Down
2 changes: 2 additions & 0 deletions src/nodes/action/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface ActionEditorNodeProperties extends EditorNodeProperties {
mustacheAltTags: boolean;
queue: string;
outputProperties: OutputProperty[];
blockInputOverrides: boolean;

// deprecated
domain?: string;
Expand Down Expand Up @@ -84,6 +85,7 @@ const ActionEditor: EditorNodeDef<ActionEditorNodeProperties> = {
validate: haOutputs.validate,
},
queue: { value: 'none' },
blockInputOverrides: { value: true },

// deprecated
domain: { value: '' },
Expand Down
5 changes: 5 additions & 0 deletions src/nodes/action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/nodes/action/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions src/nodes/action/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
},
Expand Down
22 changes: 21 additions & 1 deletion test/migrations/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit 8dd947f

Please sign in to comment.