diff --git a/src/common/constants.ts b/src/common/constants.ts index f090a1c..b7bba02 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -1,2 +1,3 @@ export const NODES_CATEGORY = 'philip tv'; export const NODES_COLOR = '#E28413'; +export const NODES_ICONS = 'font-awesome/fa-tv'; diff --git a/src/common/httpClient.ts b/src/common/httpClient.ts index 8910a91..1e82dcc 100644 --- a/src/common/httpClient.ts +++ b/src/common/httpClient.ts @@ -1,7 +1,9 @@ import { PhilTVApi } from 'philtv-js'; import type { TVConfig } from '../nodes/philips-tv-config/types'; -export function getTvApi(config: TVConfig) { +type GetTvApiParams = Omit; + +export function getTvApi(config: GetTvApiParams) { return new PhilTVApi({ apiUrl: config.url, user: config.digest_user, diff --git a/src/nodes/ambilight/editor/index.ts b/src/nodes/ambilight/editor/index.ts index 91562df..55652a6 100644 --- a/src/nodes/ambilight/editor/index.ts +++ b/src/nodes/ambilight/editor/index.ts @@ -1,5 +1,5 @@ import { type NodeEditorProps, createEditorNode, createReactiveField, domHelper } from '@keload/node-red-dxp/editor'; -import { NODES_CATEGORY, NODES_COLOR } from '../../../common/constants'; +import { NODES_CATEGORY, NODES_COLOR, NODES_ICONS } from '../../../common/constants'; import { actionsDefinition, assumedValues } from '../node-config'; import type { NodeAmbilightProps } from '../types'; @@ -15,7 +15,7 @@ const Ambilight = createEditorNode>({ }, inputs: 1, outputs: 1, - icon: 'font-awesome/fa-tower-broadcast', + icon: NODES_ICONS, label: function () { return this.name || this.action || 'Ambilight'; }, diff --git a/src/nodes/info/editor/index.ts b/src/nodes/info/editor/index.ts index d8879ce..0e84ba2 100644 --- a/src/nodes/info/editor/index.ts +++ b/src/nodes/info/editor/index.ts @@ -1,5 +1,5 @@ import { type NodeEditorProps, createEditorNode, domHelper } from '@keload/node-red-dxp/editor'; -import { NODES_CATEGORY, NODES_COLOR } from '../../../common/constants'; +import { NODES_CATEGORY, NODES_COLOR, NODES_ICONS } from '../../../common/constants'; import nodeConfig from '../node-config'; import type { InfoNodeProps } from '../types'; @@ -13,7 +13,7 @@ const Info = createEditorNode>({ }, inputs: 1, outputs: 1, - icon: 'font-awesome/fa-tower-broadcast', + icon: NODES_ICONS, label: function () { return this.name || this.kind || 'Info'; }, diff --git a/src/nodes/philips-tv-config/controller.ts b/src/nodes/philips-tv-config/controller.ts index 1a23a6f..c7fffc5 100644 --- a/src/nodes/philips-tv-config/controller.ts +++ b/src/nodes/philips-tv-config/controller.ts @@ -1,10 +1,13 @@ import type { NodeControllerConfig, NodeControllerInst } from '@keload/node-red-dxp/editor'; import type { TVConfig } from './types'; +export const credentials = { + digest_user: { type: 'text' }, + digest_password: { type: 'password' }, +}; + export default function (this: NodeControllerInst, config: NodeControllerConfig) { RED.nodes.createNode(this, config); this.name = config.name; this.url = config.url; - this.digest_user = config.digest_user; - this.digest_password = config.digest_password; } diff --git a/src/nodes/philips-tv-config/editor/index.ts b/src/nodes/philips-tv-config/editor/index.ts index 8925b25..22f9556 100644 --- a/src/nodes/philips-tv-config/editor/index.ts +++ b/src/nodes/philips-tv-config/editor/index.ts @@ -5,11 +5,14 @@ interface NodeProps { name: string; url: string; ip: string; +} + +interface NodeCredentials { digest_user: string; digest_password: string; } -export default createEditorNode>({ +export default createEditorNode, NodeCredentials>({ category: 'config', defaults: { name: { value: '', required: true }, @@ -19,8 +22,10 @@ export default createEditorNode>({ required: true, validate: (v) => validators.isIP(v), }, - digest_user: { value: '', required: true }, - digest_password: { value: '', required: true }, + }, + credentials: { + digest_user: { type: 'text' }, + digest_password: { type: 'password' }, }, label: function () { return this.name || 'Philips TV Configuration'; diff --git a/src/nodes/philips-tv-config/utils.ts b/src/nodes/philips-tv-config/utils.ts index a6cbb89..90c8d89 100644 --- a/src/nodes/philips-tv-config/utils.ts +++ b/src/nodes/philips-tv-config/utils.ts @@ -5,7 +5,13 @@ import type { TVConfig } from './types'; export function getPhilipsTvCore(RED: NodeAPI, tvNodeId: string) { const tvConfig = RED.nodes.getNode(tvNodeId) as unknown as TVConfig; - const tvClient = getTvApi(tvConfig); + const tvClient = getTvApi({ + url: tvConfig.url, + // @ts-ignore + digest_user: tvConfig.credentials.digest_user, + // @ts-ignore + digest_password: tvConfig.credentials.digest_password, + }); return { tvClient, diff --git a/src/nodes/send-key/editor/index.ts b/src/nodes/send-key/editor/index.ts index f2db2b4..6081ebf 100644 --- a/src/nodes/send-key/editor/index.ts +++ b/src/nodes/send-key/editor/index.ts @@ -1,5 +1,5 @@ import { type NodeEditorProps, createEditorNode, domHelper } from '@keload/node-red-dxp/editor'; -import { NODES_CATEGORY, NODES_COLOR } from '../../../common/constants'; +import { NODES_CATEGORY, NODES_COLOR, NODES_ICONS } from '../../../common/constants'; import { inputKeysSelect } from '../node-config'; import type { NodeSendKeyProps } from '../types'; @@ -13,7 +13,7 @@ const SendKey = createEditorNode>({ }, inputs: 1, outputs: 1, - icon: 'font-awesome/fa-tower-broadcast', + icon: NODES_ICONS, label: function () { return this.name || this.key || 'SendKey'; },