Skip to content

Commit

Permalink
feat(sentence): Add device id to output properties
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Apr 12, 2024
1 parent 629c1c5 commit 8f1ccd9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/common/services/TypedInputService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default class TypedInputService {
break;
}
case TypedInputTypes.Data:
case TypedInputTypes.DeviceId:
case TypedInputTypes.Entity:
case TypedInputTypes.EntityState:
case TypedInputTypes.EventData:
Expand Down
1 change: 1 addition & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export enum TypedInputTypes {
Value = 'value',
PreviousValue = 'previousValue',
CalendarItem = 'calendarItem',
DeviceId = 'deviceId',
}

export enum TimeUnit {
Expand Down
2 changes: 1 addition & 1 deletion src/editor/components/output-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let _extraTypes: string[] = [];

const customTypes: { [key: string]: EditorWidgetTypedInputTypeDefinition } = {
config: { value: 'config', label: 'config.', hasValue: true },
deviceId: { value: 'triggerId', label: 'device id', hasValue: false },
deviceId: { value: 'deviceId', label: 'device id', hasValue: false },
entity: { value: 'entity', label: 'entity', hasValue: false },
entityId: { value: 'triggerId', label: 'entity id', hasValue: false },
entityState: {
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/device/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ const DeviceEditor: EditorNodeDef<DeviceEditorNodeProperties> = {
const getExtraTypes = (type: 'action' | 'trigger') => {
const extraTypes = {
action: ['sentData'],
trigger: ['eventData', 'deviceId'],
trigger: ['eventData', 'triggerId'],
};
return extraTypes[type];
};
Expand Down
11 changes: 7 additions & 4 deletions src/nodes/sentence/SentenceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import ExposeAsMixin from '../../common/controllers/ExposeAsMixin';
import OutputController from '../../common/controllers/OutputController';
import { NodeMessage } from '../../types/nodes';
import { SentenceNode } from '.';
import { TypedInputTypes } from '../../const';

interface SentenceResponse {
sentence: string;
result: Record<string, unknown>;
result: Record<string, unknown> | null;
deviceId: string | null;
}

const ExposeAsController = ExposeAsMixin(OutputController<SentenceNode>);
Expand All @@ -18,9 +20,10 @@ export default class SentenseController extends ExposeAsController {
this.node.config.outputProperties,
message,
{
config: this.node.config,
triggerId: data.sentence,
results: data.result,
[TypedInputTypes.Config]: this.node.config,
[TypedInputTypes.TriggerId]: data.sentence,
[TypedInputTypes.Results]: data.result,
[TypedInputTypes.DeviceId]: data.deviceId,
},
);
this.status.setSuccess('home-assistant.status.triggered');
Expand Down
10 changes: 7 additions & 3 deletions src/nodes/sentence/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ const SentenceEditor: EditorNodeDef<SentenceEditorNodeProperties> = {
value: [
{
property: 'topic',
propertyType: 'msg',
propertyType: TypedInputTypes.Message,
value: '',
valueType: TypedInputTypes.TriggerId,
},
{
property: 'payload',
propertyType: 'msg',
propertyType: TypedInputTypes.Message,
value: '',
valueType: TypedInputTypes.TriggerId,
},
Expand Down Expand Up @@ -92,7 +92,11 @@ const SentenceEditor: EditorNodeDef<SentenceEditorNodeProperties> = {
);

haOutputs.createOutputs(this.outputProperties, {
extraTypes: ['triggerId', 'results'],
extraTypes: [
TypedInputTypes.TriggerId,
TypedInputTypes.Results,
TypedInputTypes.DeviceId,
],
});
},
oneditsave: function () {
Expand Down

0 comments on commit 8f1ccd9

Please sign in to comment.