node-red-contrib-uos-nats 0.1.32 → 0.1.34

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.
@@ -51,16 +51,29 @@ module.exports = function (RED) {
51
51
  // Helper to find definition by ID (fuzzy match string/number)
52
52
  const getDef = (id) => defMap.get(id) || defMap.get(String(id)) || defMap.get(Number(id));
53
53
 
54
- return states
55
- .map((state) => ({
56
- providerId: this.providerId,
57
- id: state.id,
58
- key: getDef(state.id)?.key || state.id,
59
- value: state.value,
60
- quality: state.quality,
61
- timestampNs: state.timestampNs,
62
- }))
63
- .filter((state) => shouldInclude(state.key));
54
+ const mapped = states.map((state) => ({
55
+ providerId: this.providerId,
56
+ id: state.id,
57
+ key: getDef(state.id)?.key || state.id,
58
+ value: state.value,
59
+ quality: state.quality,
60
+ timestampNs: state.timestampNs,
61
+ }));
62
+
63
+ // Warn if we have filters but no definitions (all keys will be raw IDs)
64
+ if (this.variables.length > 0 && defMap.size === 0 && mapped.length > 0) {
65
+ this.warnOnce('Filtering active but Variable Definitions failed to load (API Error). Names cannot be resolved, so filters will likely block all data. Please fix the API error (check Provider ID/Permissions).');
66
+ }
67
+
68
+ return mapped.filter((state) => shouldInclude(state.key));
69
+ };
70
+
71
+ // Helper to warn only once per deployment to avoid log spam
72
+ this.warnOnce = (msg) => {
73
+ if (!this.warned) {
74
+ this.warn(msg);
75
+ this.warned = true;
76
+ }
64
77
  };
65
78
 
66
79
  let performSnapshot = async () => { }; // Placeholder
@@ -83,19 +96,38 @@ module.exports = function (RED) {
83
96
  this.status({ fill: 'green', shape: 'dot', text: 'connected' });
84
97
 
85
98
  performSnapshot = async () => {
86
- // Only request snapshot if connected
87
- if (!nc || nc.isClosed()) return;
99
+ // Debugging connection state
100
+ if (!nc || nc.isClosed()) {
101
+ this.warn('Snapshot skipped: Connection is closed or not ready.');
102
+ return;
103
+ }
104
+
88
105
  try {
106
+ // Log before request
107
+ // this.warn(`Requesting snapshot for ${this.providerId}... (DefMap size: ${defMap.size})`);
108
+
89
109
  const snapshotMsg = await nc.request(subjects.readVariablesQuery(this.providerId), payloads.buildReadVariablesQuery(), { timeout: 2000 });
110
+
90
111
  const bb = new flatbuffers.ByteBuffer(snapshotMsg.data);
91
112
  const snapshotObj = ReadVariablesQueryResponse.getRootAsReadVariablesQueryResponse(bb);
92
113
  const states = payloads.decodeVariableList(snapshotObj.variables());
114
+
115
+ // this.warn(`Received ${states.length} items from NATS.`);
116
+
93
117
  const filteredSnapshot = processStates(states);
118
+
119
+ // this.warn(`Filtered down to ${filteredSnapshot.length} items. (Selected vars: ${this.variables.length})`);
120
+
94
121
  if (filteredSnapshot.length) {
95
122
  this.send({ payload: { type: 'snapshot', variables: filteredSnapshot } });
123
+ } else {
124
+ if (states.length > 0) {
125
+ this.warn(`Snapshot received data but everything was filtered out. Check Variable selection. Debug: First raw ID: ${states[0].id}, DefMap has it? ${defMap.has(states[0].id)}`);
126
+ } else {
127
+ this.warn('Snapshot received empty list from Data Hub.');
128
+ }
96
129
  }
97
130
  } catch (requestErr) {
98
- // Log snapshot failures to help debugging
99
131
  this.warn(`Snapshot failed: ${requestErr.message}`);
100
132
  }
101
133
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-uos-nats",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "description": "Node-RED nodes for u-OS Data Hub via NATS",
5
5
  "repository": {
6
6
  "type": "git",