node-red-contrib-unifi-ultimate 1.0.2 → 1.0.3

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.
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ function parseBoolean(value) {
4
+ return value === true || value === "true" || value === 1 || value === "1";
5
+ }
6
+
7
+ function parseIntervalSeconds(value, fallback) {
8
+ const numeric = Number(value);
9
+ if (!Number.isFinite(numeric) || numeric < 5) {
10
+ return fallback;
11
+ }
12
+ return Math.trunc(numeric);
13
+ }
14
+
15
+ function buildStatusTimestampText() {
16
+ const now = new Date();
17
+ const time = now.toTimeString().split(" ")[0];
18
+ return `(day ${now.getDate()}, ${time})`;
19
+ }
20
+
21
+ function appendStatusTimestamp(text) {
22
+ const normalized = String(text === undefined || text === null ? "" : text).trim();
23
+ const suffix = buildStatusTimestampText();
24
+ return normalized ? `${normalized} ${suffix}` : suffix;
25
+ }
26
+
27
+ function resolveNodeName(value) {
28
+ return String(value || "").trim();
29
+ }
30
+
31
+ function resolveDeviceName(value) {
32
+ return String(value || "").trim();
33
+ }
34
+
35
+ // Superset version — includes hostname and macAddress for Network nodes; harmless for Protect/Access.
36
+ function extractDeviceNameFromPayload(payload) {
37
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
38
+ return "";
39
+ }
40
+
41
+ return resolveDeviceName(
42
+ payload.name
43
+ || payload.displayName
44
+ || payload.hostname
45
+ || payload.alias
46
+ || payload.full_name
47
+ || payload.macAddress
48
+ || payload.id
49
+ );
50
+ }
51
+
52
+ function attachDeviceNameToPayload(payload, deviceName) {
53
+ if (!deviceName) {
54
+ return payload;
55
+ }
56
+
57
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
58
+ return {
59
+ ...payload,
60
+ deviceName
61
+ };
62
+ }
63
+
64
+ return payload;
65
+ }
66
+
67
+ function attachDetails(outputMsg, details) {
68
+ if (!outputMsg || typeof outputMsg !== "object" || Array.isArray(outputMsg)) {
69
+ return;
70
+ }
71
+ if (!details || typeof details !== "object" || Array.isArray(details)) {
72
+ return;
73
+ }
74
+
75
+ outputMsg.details = {
76
+ ...(outputMsg.details && typeof outputMsg.details === "object" && !Array.isArray(outputMsg.details)
77
+ ? outputMsg.details
78
+ : {}),
79
+ ...details
80
+ };
81
+ }
82
+
83
+ function buildErrorOutputMessage(error, nodeName) {
84
+ return {
85
+ topic: String(nodeName || "").trim() || undefined,
86
+ payload: null,
87
+ error: {
88
+ message: String(error && error.message ? error.message : error)
89
+ }
90
+ };
91
+ }
92
+
93
+ module.exports = {
94
+ parseBoolean,
95
+ parseIntervalSeconds,
96
+ buildStatusTimestampText,
97
+ appendStatusTimestamp,
98
+ resolveNodeName,
99
+ resolveDeviceName,
100
+ extractDeviceNameFromPayload,
101
+ attachDeviceNameToPayload,
102
+ attachDetails,
103
+ buildErrorOutputMessage
104
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-unifi-ultimate",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Node-RED nodes for Ubiquiti UniFi integrations, including UniFi Protect, UniFi Access, and UniFi Network.",
5
5
  "files": [
6
6
  "nodes/",
@@ -46,7 +46,7 @@
46
46
  }
47
47
  },
48
48
  "scripts": {
49
- "test": "node --check nodes/unifi-access-config.js && node --check nodes/unifi-access-device.js && node --check nodes/unifi-network-config.js && node --check nodes/unifi-network-control-poe.js && node --check nodes/unifi-network-device.js && node --check nodes/unifi-network-presence.js && node --check nodes/unifi-protect-config.js && node --check nodes/unifi-protect-device.js && node --check nodes/utils/http-response-utils.js && node --check nodes/utils/unifi-access-utils.js && node --check nodes/utils/unifi-access-device-registry.js && node --check nodes/utils/unifi-network-utils.js && node --check nodes/utils/unifi-network-device-registry.js && node --check nodes/utils/unifi-protect-utils.js && node --check nodes/utils/unifi-protect-field-metadata.js && node --check nodes/utils/unifi-protect-device-registry.js && node --check scripts/unifi-registry-discovery-common.js && node --check scripts/discover-unifi-network-registry.js && node --check scripts/discover-unifi-protect-registry.js && node --check scripts/discover-unifi-access-registry.js",
49
+ "test": "node --check nodes/unifi-access-config.js && node --check nodes/unifi-access-device.js && node --check nodes/unifi-network-config.js && node --check nodes/unifi-network-control-poe.js && node --check nodes/unifi-network-device.js && node --check nodes/unifi-network-presence.js && node --check nodes/unifi-protect-config.js && node --check nodes/unifi-protect-device.js && node --check nodes/utils/common-utils.js && node --check nodes/utils/http-response-utils.js && node --check nodes/utils/unifi-access-utils.js && node --check nodes/utils/unifi-access-device-registry.js && node --check nodes/utils/unifi-network-utils.js && node --check nodes/utils/unifi-network-device-registry.js && node --check nodes/utils/unifi-protect-utils.js && node --check nodes/utils/unifi-protect-field-metadata.js && node --check nodes/utils/unifi-protect-device-registry.js && node --check scripts/unifi-registry-discovery-common.js && node --check scripts/discover-unifi-network-registry.js && node --check scripts/discover-unifi-protect-registry.js && node --check scripts/discover-unifi-access-registry.js && jest",
50
50
  "registry:discover:network": "node scripts/discover-unifi-network-registry.js",
51
51
  "registry:discover:protect": "node scripts/discover-unifi-protect-registry.js",
52
52
  "registry:discover:access": "node scripts/discover-unifi-access-registry.js"
@@ -55,7 +55,9 @@
55
55
  "directories": {
56
56
  "example": "examples"
57
57
  },
58
- "devDependencies": {},
58
+ "devDependencies": {
59
+ "jest": "^30.4.2"
60
+ },
59
61
  "type": "commonjs",
60
62
  "bugs": {
61
63
  "url": "https://github.com/Supergiovane/node-red-contrib-unifi-ultimate/issues"