node-red-contrib-power-genius 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,63 +1,63 @@
1
- module.exports = (RED) => {
2
- class PowerGeniusInfo {
3
- constructor(config) {
4
- RED.nodes.createNode(this, config);
5
- this.server = RED.nodes.getNode(config.server);
6
-
7
- if (this.server == null) {
8
- this.status({ fill: "red", shape: "ring", text: "disconnected" });
9
- return;
10
- }
11
-
12
- // "*" (or unset) emits the whole info object.
13
- const property = config.property && config.property !== "*" ? config.property : null;
14
- const startDelay = Math.max(parseInt(config.startDelay, 10) || 0, 0);
15
- let ready = false;
16
-
17
- const emit = () => {
18
- const info = this.server.info;
19
- if (Object.keys(info).length === 0) return;
20
- if (property === null) {
21
- this.send({ topic: "info", payload: { ...info } });
22
- } else if (property in info) {
23
- this.send({ topic: property, payload: info[property] });
24
- }
25
- };
26
-
27
- const emitter = this.server.updatesEventEmitter;
28
-
29
- const onConnected = () => {
30
- this.status({ fill: "green", shape: "dot", text: this.server.info.name || "connected" });
31
- if (ready) emit();
32
- };
33
- const onClosed = () => {
34
- this.status({ fill: "red", shape: "ring", text: "disconnected" });
35
- };
36
-
37
- emitter.on("connected", onConnected);
38
- emitter.on("closed", onClosed);
39
-
40
- // Hold back output after deploy so that downstream nodes (e.g. dashboard UI) can finish initializing.
41
- // Also covers a server that is already connected, which does not emit "connected" again.
42
- const startTimer = setTimeout(() => {
43
- ready = true;
44
- emit();
45
- }, startDelay);
46
-
47
- this.on("input", async (msg, send, done) => {
48
- await this.server.refreshInfo();
49
- emit();
50
- if (done) done();
51
- });
52
-
53
- this.on("close", () => {
54
- clearTimeout(startTimer);
55
- emitter.removeListener("connected", onConnected);
56
- emitter.removeListener("closed", onClosed);
57
- });
58
-
59
- this.server.connect();
60
- }
61
- }
62
- RED.nodes.registerType("power-genius-info", PowerGeniusInfo);
63
- };
1
+ module.exports = (RED) => {
2
+ class PowerGeniusInfo {
3
+ constructor(config) {
4
+ RED.nodes.createNode(this, config);
5
+ this.server = RED.nodes.getNode(config.server);
6
+
7
+ if (this.server == null) {
8
+ this.status({ fill: "red", shape: "ring", text: "disconnected" });
9
+ return;
10
+ }
11
+
12
+ // "*" (or unset) emits the whole info object.
13
+ const property = config.property && config.property !== "*" ? config.property : null;
14
+ const startDelay = Math.max(parseInt(config.startDelay, 10) || 0, 0);
15
+ let ready = false;
16
+
17
+ const emit = () => {
18
+ const info = this.server.info;
19
+ if (Object.keys(info).length === 0) return;
20
+ if (property === null) {
21
+ this.send({ topic: "info", payload: { ...info } });
22
+ } else if (property in info) {
23
+ this.send({ topic: property, payload: info[property] });
24
+ }
25
+ };
26
+
27
+ const emitter = this.server.updatesEventEmitter;
28
+
29
+ const onConnected = () => {
30
+ this.status({ fill: "green", shape: "dot", text: this.server.info.name || "connected" });
31
+ if (ready) emit();
32
+ };
33
+ const onClosed = () => {
34
+ this.status({ fill: "red", shape: "ring", text: "disconnected" });
35
+ };
36
+
37
+ emitter.on("connected", onConnected);
38
+ emitter.on("closed", onClosed);
39
+
40
+ // Hold back output after deploy so that downstream nodes (e.g. dashboard UI) can finish initializing.
41
+ // Also covers a server that is already connected, which does not emit "connected" again.
42
+ const startTimer = setTimeout(() => {
43
+ ready = true;
44
+ emit();
45
+ }, startDelay);
46
+
47
+ this.on("input", async (msg, send, done) => {
48
+ await this.server.refreshInfo();
49
+ emit();
50
+ if (done) done();
51
+ });
52
+
53
+ this.on("close", () => {
54
+ clearTimeout(startTimer);
55
+ emitter.removeListener("connected", onConnected);
56
+ emitter.removeListener("closed", onClosed);
57
+ });
58
+
59
+ this.server.connect();
60
+ }
61
+ }
62
+ RED.nodes.registerType("power-genius-info", PowerGeniusInfo);
63
+ };
@@ -1,54 +1,54 @@
1
- <script type="text/javascript">
2
- RED.nodes.registerType("power-genius-server", {
3
- category: "config",
4
- defaults: {
5
- host: { value: "localhost", required: true },
6
- port: { value: 9008, required: true, validate: RED.validators.number() },
7
- autoConnect: { value: true },
8
- pollInterval: { value: 1000, validate: RED.validators.number() },
9
- },
10
- label: function () {
11
- return "power genius at " + this.host + ":" + this.port;
12
- },
13
- });
14
- </script>
15
-
16
- <script type="text/html" data-template-name="power-genius-server">
17
- <div class="form-row">
18
- <label for="node-config-input-host"><i class="fa fa-bookmark"></i> Host</label>
19
- <input type="text" id="node-config-input-host" />
20
- </div>
21
- <div class="form-row">
22
- <label for="node-config-input-port"><i class="fa fa-bookmark"></i> Port</label>
23
- <input type="text" id="node-config-input-port" />
24
- </div>
25
- <div class="form-row">
26
- <label for="node-config-input-autoConnect"><i class="fa fa-plug"></i> Auto connect</label>
27
- <input type="checkbox" id="node-config-input-autoConnect" style="width:auto" />
28
- </div>
29
- <div class="form-row">
30
- <label for="node-config-input-pollInterval"><i class="fa fa-clock-o"></i> Poll (ms)</label>
31
- <input type="text" id="node-config-input-pollInterval" />
32
- </div>
33
- </script>
34
-
35
- <script type="text/markdown" data-help-name="power-genius-server">
36
- Power Genius shared connection configuration (PGXL TCP API).
37
-
38
- The nodes share one TCP connection to the amplifier. After connecting, the device sends its firmware version
39
- (with `AUTH` appended when it requires authentication, which is only the case outside the local network and is
40
- not supported yet). Commands are answered immediately, so the status is read by polling.
41
-
42
- ### Configuration
43
-
44
- : Host (string) : Power Genius host name or IP address.
45
-
46
- : Port (integer) : Power Genius API port number. The device uses 9008.
47
-
48
- : Auto connect (boolean) : Connect and reconnect automatically (retries every 5 seconds).
49
-
50
- : Poll (ms) : How often to read `status` from the device, in milliseconds. 0 disables polling, in which case
51
- status nodes only get the value read at connect time, and a fresh one on each input message.
52
-
53
- Set the Node-RED log level to `trace` to see every line received from the amplifier.
54
- </script>
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType("power-genius-server", {
3
+ category: "config",
4
+ defaults: {
5
+ host: { value: "localhost", required: true },
6
+ port: { value: 9008, required: true, validate: RED.validators.number() },
7
+ autoConnect: { value: true },
8
+ pollInterval: { value: 1000, validate: RED.validators.number() },
9
+ },
10
+ label: function () {
11
+ return "power genius at " + this.host + ":" + this.port;
12
+ },
13
+ });
14
+ </script>
15
+
16
+ <script type="text/html" data-template-name="power-genius-server">
17
+ <div class="form-row">
18
+ <label for="node-config-input-host"><i class="fa fa-bookmark"></i> Host</label>
19
+ <input type="text" id="node-config-input-host" />
20
+ </div>
21
+ <div class="form-row">
22
+ <label for="node-config-input-port"><i class="fa fa-bookmark"></i> Port</label>
23
+ <input type="text" id="node-config-input-port" />
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-config-input-autoConnect"><i class="fa fa-plug"></i> Auto connect</label>
27
+ <input type="checkbox" id="node-config-input-autoConnect" style="width:auto" />
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-config-input-pollInterval"><i class="fa fa-clock-o"></i> Poll (ms)</label>
31
+ <input type="text" id="node-config-input-pollInterval" />
32
+ </div>
33
+ </script>
34
+
35
+ <script type="text/markdown" data-help-name="power-genius-server">
36
+ Power Genius shared connection configuration (PGXL TCP API).
37
+
38
+ The nodes share one TCP connection to the amplifier. After connecting, the device sends its firmware version
39
+ (with `AUTH` appended when it requires authentication, which is only the case outside the local network and is
40
+ not supported yet). Commands are answered immediately, so the status is read by polling.
41
+
42
+ ### Configuration
43
+
44
+ : Host (string) : Power Genius host name or IP address.
45
+
46
+ : Port (integer) : Power Genius API port number. The device uses 9008.
47
+
48
+ : Auto connect (boolean) : Connect and reconnect automatically (retries every 5 seconds).
49
+
50
+ : Poll (ms) : How often to read `status` from the device, in milliseconds. 0 disables polling, in which case
51
+ status nodes only get the value read at connect time, and a fresh one on each input message.
52
+
53
+ Set the Node-RED log level to `trace` to see every line received from the amplifier.
54
+ </script>