Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
clement-berard committed Nov 22, 2024
1 parent 535367f commit 87052aa
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const NODES_CATEGORY = 'philip tv';
export const NODES_COLOR = '#E28413';
export const NODES_ICONS = 'font-awesome/fa-tv';
4 changes: 3 additions & 1 deletion src/common/httpClient.ts
Original file line number Diff line number Diff line change
@@ -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<TVConfig, 'name' | 'ip'>;

export function getTvApi(config: GetTvApiParams) {
return new PhilTVApi({
apiUrl: config.url,
user: config.digest_user,
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/ambilight/editor/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -15,7 +15,7 @@ const Ambilight = createEditorNode<NodeEditorProps<NodeAmbilightProps>>({
},
inputs: 1,
outputs: 1,
icon: 'font-awesome/fa-tower-broadcast',
icon: NODES_ICONS,
label: function () {
return this.name || this.action || 'Ambilight';
},
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/info/editor/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,7 +13,7 @@ const Info = createEditorNode<NodeEditorProps<InfoNodeProps>>({
},
inputs: 1,
outputs: 1,
icon: 'font-awesome/fa-tower-broadcast',
icon: NODES_ICONS,
label: function () {
return this.name || this.kind || 'Info';
},
Expand Down
7 changes: 5 additions & 2 deletions src/nodes/philips-tv-config/controller.ts
Original file line number Diff line number Diff line change
@@ -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<TVConfig>, config: NodeControllerConfig<TVConfig>) {
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;
}
11 changes: 8 additions & 3 deletions src/nodes/philips-tv-config/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ interface NodeProps {
name: string;
url: string;
ip: string;
}

interface NodeCredentials {
digest_user: string;
digest_password: string;
}

export default createEditorNode<NodeEditorProps<NodeProps>>({
export default createEditorNode<NodeEditorProps<NodeProps>, NodeCredentials>({
category: 'config',
defaults: {
name: { value: '', required: true },
Expand All @@ -19,8 +22,10 @@ export default createEditorNode<NodeEditorProps<NodeProps>>({
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';
Expand Down
8 changes: 7 additions & 1 deletion src/nodes/philips-tv-config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/send-key/editor/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,7 +13,7 @@ const SendKey = createEditorNode<NodeEditorProps<NodeSendKeyProps>>({
},
inputs: 1,
outputs: 1,
icon: 'font-awesome/fa-tower-broadcast',
icon: NODES_ICONS,
label: function () {
return this.name || this.key || 'SendKey';
},
Expand Down

0 comments on commit 87052aa

Please sign in to comment.