From b805cf881a60e41729afeea9e7d5b356c3c5a2d0 Mon Sep 17 00:00:00 2001
From: Jason <37859597+zachowj@users.noreply.github.com>
Date: Mon, 8 Jan 2024 17:54:54 -0800
Subject: [PATCH] fix: Fix TS types
---
src/editor/editors/entity-filter.ts | 6 ++++--
src/editor/exposenode.ts | 10 ++++++----
src/editor/sidebar/index.ts | 2 +-
src/editor/types.ts | 6 +++---
src/editor/version.ts | 4 ++--
src/nodes/number/editor.ts | 9 +++------
src/nodes/select/editor.ts | 9 +++------
src/nodes/switch/editor.ts | 9 +++------
src/nodes/text/editor.ts | 9 +++------
src/nodes/time-entity/editor.ts | 9 +++------
src/nodes/trigger-state/editor.ts | 9 +++------
src/nodes/wait-until/editor.ts | 12 +++++++-----
12 files changed, 41 insertions(+), 53 deletions(-)
diff --git a/src/editor/editors/entity-filter.ts b/src/editor/editors/entity-filter.ts
index af8a4ce1ee..1cd0859978 100644
--- a/src/editor/editors/entity-filter.ts
+++ b/src/editor/editors/entity-filter.ts
@@ -16,7 +16,7 @@ const filterIds = (
filter: string,
filterType: 'regex' | 'substring',
) => {
- let results: HassEntity[];
+ let results: HassEntity[] = [];
if (filterType === 'regex') {
try {
const regex = new RegExp(filter);
@@ -98,7 +98,8 @@ export const entityFilter = {
.trigger('input');
},
};
- RED.tray.show(trayOptions);
+ // TODO: Fix types find a way to get the type of the trayOptions object
+ RED.tray.show(trayOptions as any);
},
};
@@ -114,6 +115,7 @@ export const openEntityFilter = ({
complete: (filter: string) => void;
}) => {
RED.editor.showTypeEditor('ha_entity_filter', {
+ // @ts-expect-error - filter is an acceptable argument, DefinitelyTyped is wrong
filter,
filterType,
entities,
diff --git a/src/editor/exposenode.ts b/src/editor/exposenode.ts
index 7b20dea548..9b82021639 100644
--- a/src/editor/exposenode.ts
+++ b/src/editor/exposenode.ts
@@ -26,7 +26,9 @@ function isEntityNode() {
NodeType.Text,
NodeType.TimeEntity,
];
- return node?.type && nodes.includes(node.type);
+ return (
+ 'type' in node && node?.type && nodes.includes(node.type as NodeType)
+ );
}
function getServerId(): string | undefined {
@@ -65,7 +67,7 @@ function isAddNodeSelected(selector: 'entityConfig' | 'server') {
export function init(n: HassNodeProperties) {
node = n;
- const type = node.type as unknown as NodeType;
+ const type = 'type' in node && (node.type as unknown as NodeType);
render();
$('#node-input-server, #node-input-entityConfig').on('change', () => {
@@ -106,7 +108,7 @@ export function init(n: HassNodeProperties) {
}
function render() {
- const type = node.type as unknown as NodeType;
+ const type = 'type' in node && (node.type as unknown as NodeType);
switch (type) {
case NodeType.BinarySensor:
@@ -146,7 +148,7 @@ function renderEventNode() {
const $row = $('
', {
id: 'exposeToHa',
class: `form-row checkbox-option${
- node.type === 'trigger-state' ? '-left' : ''
+ 'type' in node && node.type === 'trigger-state' ? '-left' : ''
}`,
});
$('', {
diff --git a/src/editor/sidebar/index.ts b/src/editor/sidebar/index.ts
index 7a684ce538..1920b7dcb8 100644
--- a/src/editor/sidebar/index.ts
+++ b/src/editor/sidebar/index.ts
@@ -24,7 +24,7 @@ export function initSidebar() {
id: 'ha_sidebar',
label: 'Home Assistant',
name: 'Home Assistant',
- content,
+ content: content.get(0),
closeable: true,
disableOnEdit: true,
iconClass: 'fa fa-home',
diff --git a/src/editor/types.ts b/src/editor/types.ts
index c78dae02f0..a2d96a723c 100644
--- a/src/editor/types.ts
+++ b/src/editor/types.ts
@@ -34,17 +34,17 @@ export interface EditorWidgetEditableListOptions
buttons: EditorWidgetEditableListButton[];
}
-export interface HassNodeProperties
- extends Omit {
+export interface HassNodeProperties extends EditorNodeProperties {
version: number;
debugenabled?: boolean;
server?: string;
entityConfigNode?: string;
+ exposeAsEntityConfig?: string;
outputs?: number | undefined;
- haConfig?: HassExposedConfig[];
// TODO: remove after controllers are converted to TypeScript
exposeToHomeAssistant?: boolean;
+ haConfig?: HassExposedConfig[];
}
export interface HassTargetDomains {
diff --git a/src/editor/version.ts b/src/editor/version.ts
index cc31abc013..f30bae3826 100644
--- a/src/editor/version.ts
+++ b/src/editor/version.ts
@@ -72,7 +72,7 @@ function migrateNode(node: EditorNodeInstance) {
const migratedData: HassNodeProperties = migrate(data);
// TODO: Remove for version 1.0
- if (migratedData.type === NodeType.Entity) {
+ if ('type' in migratedData && migratedData.type === NodeType.Entity) {
convertEntityNode(migratedData as unknown as EntityProperties);
} else if (haConfig) {
convertEventNode(migratedData as unknown as EntityProperties, haConfig);
@@ -187,7 +187,7 @@ function isHomeAssistantConfigNode(
NodeType.Server,
NodeType.EntityConfig,
NodeType.DeviceConfig,
- ].includes(node.type)
+ ].includes(node.type as unknown as NodeType)
);
}
diff --git a/src/nodes/number/editor.ts b/src/nodes/number/editor.ts
index 2fdb74504b..a3eb7d4ff8 100644
--- a/src/nodes/number/editor.ts
+++ b/src/nodes/number/editor.ts
@@ -1,4 +1,4 @@
-import { EditorNodeDef, EditorNodeProperties, EditorRED } from 'node-red';
+import { EditorNodeDef, EditorRED } from 'node-red';
import {
EntityType,
@@ -9,14 +9,12 @@ import {
import * as haOutputs from '../../editor/components/output-properties';
import * as exposeNode from '../../editor/exposenode';
import ha, { NodeCategory, NodeColor } from '../../editor/ha';
-import { OutputProperty } from '../../editor/types';
+import { HassNodeProperties, OutputProperty } from '../../editor/types';
import { saveEntityType } from '../entity-config/editor/helpers';
declare const RED: EditorRED;
-interface NumberEditorNodeProperties extends EditorNodeProperties {
- version: number;
- debugenabled: boolean;
+interface NumberEditorNodeProperties extends HassNodeProperties {
entityConfig: any;
mode: ValueIntegrationMode;
outputProperties: OutputProperty[];
@@ -38,7 +36,6 @@ const NumberEditor: EditorNodeDef = {
name: { value: '' },
version: { value: RED.settings.get('haNumberVersion', 0) },
debugenabled: { value: false },
- // @ts-expect-error - DefinitelyTyped is wrong inputs can be changed
inputs: { value: 0 },
outputs: { value: 1 },
entityConfig: {
diff --git a/src/nodes/select/editor.ts b/src/nodes/select/editor.ts
index 28979e6f1e..a4ef060103 100644
--- a/src/nodes/select/editor.ts
+++ b/src/nodes/select/editor.ts
@@ -1,4 +1,4 @@
-import { EditorNodeDef, EditorNodeProperties, EditorRED } from 'node-red';
+import { EditorNodeDef, EditorRED } from 'node-red';
import {
EntityType,
@@ -9,14 +9,12 @@ import {
import * as haOutputs from '../../editor/components/output-properties';
import * as exposeNode from '../../editor/exposenode';
import ha, { NodeCategory, NodeColor } from '../../editor/ha';
-import { OutputProperty } from '../../editor/types';
+import { HassNodeProperties, OutputProperty } from '../../editor/types';
import { saveEntityType } from '../entity-config/editor/helpers';
declare const RED: EditorRED;
-interface SelectEditorNodeProperties extends EditorNodeProperties {
- version: number;
- debugenabled: boolean;
+interface SelectEditorNodeProperties extends HassNodeProperties {
entityConfig: any;
mode: ValueIntegrationMode;
outputProperties: OutputProperty[];
@@ -38,7 +36,6 @@ const SelectEditor: EditorNodeDef = {
name: { value: '' },
version: { value: RED.settings.get('haTextVersion', 0) },
debugenabled: { value: false },
- // @ts-expect-error - DefinitelyTyped is wrong inputs can be changed
inputs: { value: 0 },
outputs: { value: 1 },
entityConfig: {
diff --git a/src/nodes/switch/editor.ts b/src/nodes/switch/editor.ts
index 5df50f72c3..8b3f222a85 100644
--- a/src/nodes/switch/editor.ts
+++ b/src/nodes/switch/editor.ts
@@ -1,17 +1,15 @@
-import { EditorNodeDef, EditorNodeProperties, EditorRED } from 'node-red';
+import { EditorNodeDef, EditorRED } from 'node-red';
import { EntityType, NodeType } from '../../const';
import * as haOutputs from '../../editor/components/output-properties';
import * as exposeNode from '../../editor/exposenode';
import ha, { NodeCategory, NodeColor } from '../../editor/ha';
-import { OutputProperty } from '../../editor/types';
+import { HassNodeProperties, OutputProperty } from '../../editor/types';
import { saveEntityType } from '../entity-config/editor/helpers';
declare const RED: EditorRED;
-interface SwitchEditorNodeProperties extends EditorNodeProperties {
- version: number;
- debugenabled: boolean;
+interface SwitchEditorNodeProperties extends HassNodeProperties {
enableInput: boolean;
entityConfig: any;
outputOnStateChange: boolean;
@@ -34,7 +32,6 @@ const SwitchEditor: EditorNodeDef = {
name: { value: '' },
version: { value: RED.settings.get('haSwitchVersion', 0) },
debugenabled: { value: false },
- // @ts-expect-error - DefinitelyTyped is wrong inputs can be changed
inputs: { value: 0 },
outputs: { value: 2 },
entityConfig: {
diff --git a/src/nodes/text/editor.ts b/src/nodes/text/editor.ts
index 182ae6b97d..78952383f3 100644
--- a/src/nodes/text/editor.ts
+++ b/src/nodes/text/editor.ts
@@ -1,4 +1,4 @@
-import { EditorNodeDef, EditorNodeProperties, EditorRED } from 'node-red';
+import { EditorNodeDef, EditorRED } from 'node-red';
import {
EntityType,
@@ -9,14 +9,12 @@ import {
import * as haOutputs from '../../editor/components/output-properties';
import * as exposeNode from '../../editor/exposenode';
import ha, { NodeCategory, NodeColor } from '../../editor/ha';
-import { OutputProperty } from '../../editor/types';
+import { HassNodeProperties, OutputProperty } from '../../editor/types';
import { saveEntityType } from '../entity-config/editor/helpers';
declare const RED: EditorRED;
-interface TextEditorNodeProperties extends EditorNodeProperties {
- version: number;
- debugenabled: boolean;
+interface TextEditorNodeProperties extends HassNodeProperties {
entityConfig: any;
mode: ValueIntegrationMode;
outputProperties: OutputProperty[];
@@ -38,7 +36,6 @@ const TextEditor: EditorNodeDef = {
name: { value: '' },
version: { value: RED.settings.get('haTextVersion', 0) },
debugenabled: { value: false },
- // @ts-expect-error - DefinitelyTyped is wrong inputs can be changed
inputs: { value: 0 },
outputs: { value: 1 },
entityConfig: {
diff --git a/src/nodes/time-entity/editor.ts b/src/nodes/time-entity/editor.ts
index c506317146..a697d3eefa 100644
--- a/src/nodes/time-entity/editor.ts
+++ b/src/nodes/time-entity/editor.ts
@@ -1,4 +1,4 @@
-import { EditorNodeDef, EditorNodeProperties, EditorRED } from 'node-red';
+import { EditorNodeDef, EditorRED } from 'node-red';
import {
EntityType,
@@ -9,14 +9,12 @@ import {
import * as haOutputs from '../../editor/components/output-properties';
import * as exposeNode from '../../editor/exposenode';
import ha, { NodeCategory, NodeColor } from '../../editor/ha';
-import { OutputProperty } from '../../editor/types';
+import { HassNodeProperties, OutputProperty } from '../../editor/types';
import { saveEntityType } from '../entity-config/editor/helpers';
declare const RED: EditorRED;
-interface TimeEntityEditorNodeProperties extends EditorNodeProperties {
- version: number;
- debugenabled: boolean;
+interface TimeEntityEditorNodeProperties extends HassNodeProperties {
entityConfig: any;
mode: ValueIntegrationMode;
value: string;
@@ -39,7 +37,6 @@ const TimeEntityEditor: EditorNodeDef = {
name: { value: '' },
version: { value: RED.settings.get('haTimeEntityVersion', 0) },
debugenabled: { value: false },
- // @ts-expect-error - DefinitelyTyped is wrong inputs can be changed
inputs: { value: 0 },
outputs: { value: 1 },
entityConfig: {
diff --git a/src/nodes/trigger-state/editor.ts b/src/nodes/trigger-state/editor.ts
index 3a3710adaa..5519142ac6 100644
--- a/src/nodes/trigger-state/editor.ts
+++ b/src/nodes/trigger-state/editor.ts
@@ -1,4 +1,4 @@
-import { EditorNodeDef, EditorNodeProperties, EditorRED } from 'node-red';
+import { EditorNodeDef, EditorRED } from 'node-red';
import { TransformType } from '../../common/TransformState';
import {
@@ -12,6 +12,7 @@ import * as exposeNode from '../../editor/exposenode';
import ha, { NodeCategory, NodeColor } from '../../editor/ha';
import * as haServer from '../../editor/haserver';
import { i18n } from '../../editor/i18n';
+import { HassNodeProperties } from '../../editor/types';
import { saveEntityType } from '../entity-config/editor/helpers';
import {
ComparatorPropertyType,
@@ -24,12 +25,9 @@ import {
declare const RED: EditorRED;
-interface TriggerStateEditorNodeProperties extends EditorNodeProperties {
- server: string;
- version: number;
+interface TriggerStateEditorNodeProperties extends HassNodeProperties {
entityId: string | string[];
entityIdType: string;
- debugEnabled: boolean;
constraints: Constraint[];
customOutputs: CustomOutput[];
outputInitially: boolean;
@@ -81,7 +79,6 @@ const TriggerStateEditor: EditorNodeDef = {
name: { value: '' },
server: { value: '', type: NodeType.Server, required: true },
version: { value: RED.settings.get('triggerStateVersion', 0) },
- // @ts-ignore - DefinitelyTyped is wrong inputs can be changed
inputs: { value: 0 },
outputs: { value: 2 },
exposeAsEntityConfig: {
diff --git a/src/nodes/wait-until/editor.ts b/src/nodes/wait-until/editor.ts
index a793380edd..62b257c6c1 100644
--- a/src/nodes/wait-until/editor.ts
+++ b/src/nodes/wait-until/editor.ts
@@ -1,4 +1,4 @@
-import { EditorNodeDef, EditorNodeProperties, EditorRED } from 'node-red';
+import { EditorNodeDef, EditorRED } from 'node-red';
import {
ComparatorType,
@@ -10,13 +10,15 @@ import EntitySelector from '../../editor/components/EntitySelector';
import * as haOutputs from '../../editor/components/output-properties';
import ha, { NodeCategory, NodeColor } from '../../editor/ha';
import * as haServer from '../../editor/haserver';
-import { HATypedInputTypeOptions, OutputProperty } from '../../editor/types';
+import {
+ HassNodeProperties,
+ HATypedInputTypeOptions,
+ OutputProperty,
+} from '../../editor/types';
declare const RED: EditorRED;
-interface WaitUntilEditorNodeProperties extends EditorNodeProperties {
- server: string;
- version: number;
+interface WaitUntilEditorNodeProperties extends HassNodeProperties {
entityId: string | string[];
entityIdFilterType: string;
property: string;