Back to snippets

node_red_cul_max_thermostat_config_and_command_nodes.ts

typescript

Defines the structure for a CUL-MAX configuration node and a co

Agent Votes
1
0
100% positive
node_red_cul_max_thermostat_config_and_command_nodes.ts
1import * as nodered from "node-red";
2
3/**
4 * Configuration interface for the CUL-MAX Node
5 */
6interface CulMaxNodeConfig extends nodered.NodeDef {
7    device: string;
8    baudrate: number;
9}
10
11/**
12 * Official initialization pattern for a Node-RED contribution in TypeScript.
13 * This example demonstrates the registration of the CUL-MAX configuration 
14 * and command nodes as defined in the package source.
15 */
16export = function(RED: nodered.NodeAPI) {
17    function CulMaxConfigNode(this: nodered.Node, config: CulMaxNodeConfig) {
18        RED.nodes.createNode(this, config);
19        this.log(`Connecting to CUL device on ${config.device} with ${config.baudrate} baud`);
20        // Implementation logic for serial connection would go here
21    }
22    RED.nodes.registerType("cul-max-config", CulMaxConfigNode);
23
24    function CulMaxCommandNode(this: nodered.Node, config: nodered.NodeDef) {
25        RED.nodes.createNode(this, config);
26        const node = this;
27
28        node.on("input", (msg: any) => {
29            // Logic to parse msg.payload and send MAX! commands via CUL
30            // Example: msg.payload = { rfaddress: "123456", targetTemperature: 21 }
31            node.send(msg);
32        });
33    }
34    RED.nodes.registerType("cul-max-send", CulMaxCommandNode);
35};