myio-js-library 0.1.209 → 0.1.211

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.
package/dist/index.cjs CHANGED
@@ -22131,12 +22131,13 @@ var WaterTankModal = class {
22131
22131
  * Build context object for callbacks
22132
22132
  */
22133
22133
  buildContext(options) {
22134
+ const displayLevel = options.currentLevelClamped ?? options.currentLevel ?? 0;
22134
22135
  return {
22135
22136
  device: {
22136
22137
  id: options.deviceId,
22137
22138
  label: options.label || options.deviceId,
22138
22139
  type: options.deviceType,
22139
- currentLevel: options.currentLevel
22140
+ currentLevel: displayLevel
22140
22141
  },
22141
22142
  metadata: {
22142
22143
  slaveId: options.slaveId,
@@ -22226,16 +22227,25 @@ var WaterTankModal = class {
22226
22227
  }
22227
22228
  /**
22228
22229
  * Transform raw ThingsBoard response to our data points
22230
+ * RFC-0107: Support displayKey option to choose between water_level or water_percentage
22229
22231
  */
22230
22232
  transformTelemetryData(rawData, keys) {
22231
22233
  const allPoints = [];
22232
- for (const key of keys) {
22234
+ const displayKey = this.options.displayKey || "water_percentage";
22235
+ const prioritizedKeys = displayKey && rawData[displayKey] ? [displayKey, ...keys.filter((k) => k !== displayKey)] : keys;
22236
+ for (const key of prioritizedKeys) {
22233
22237
  if (rawData[key] && Array.isArray(rawData[key])) {
22234
- const keyPoints = rawData[key].map((point) => ({
22235
- ts: point.ts,
22236
- value: typeof point.value === "string" ? parseFloat(point.value) : point.value,
22237
- key
22238
- }));
22238
+ const keyPoints = rawData[key].map((point) => {
22239
+ let value = typeof point.value === "string" ? parseFloat(point.value) : point.value;
22240
+ if (key === "water_percentage" && value <= 1.5) {
22241
+ value = value * 100;
22242
+ }
22243
+ return {
22244
+ ts: point.ts,
22245
+ value,
22246
+ key
22247
+ };
22248
+ });
22239
22249
  allPoints.push(...keyPoints);
22240
22250
  }
22241
22251
  }
@@ -22248,15 +22258,18 @@ var WaterTankModal = class {
22248
22258
  uniquePoints.push(point);
22249
22259
  }
22250
22260
  }
22261
+ console.log(`[WaterTankModal] Transformed ${uniquePoints.length} points, displayKey: ${displayKey}`);
22251
22262
  return uniquePoints;
22252
22263
  }
22253
22264
  /**
22254
22265
  * Calculate summary statistics from telemetry data
22266
+ * RFC-0107: Use clamped level for display
22255
22267
  */
22256
22268
  calculateSummary(telemetry) {
22269
+ const displayLevel = this.options.currentLevelClamped ?? this.options.currentLevel ?? 0;
22257
22270
  if (telemetry.length === 0) {
22258
22271
  return {
22259
- currentLevel: this.options.currentLevel,
22272
+ currentLevel: displayLevel,
22260
22273
  avgLevel: 0,
22261
22274
  minLevel: 0,
22262
22275
  maxLevel: 0,
package/dist/index.d.cts CHANGED
@@ -1729,10 +1729,14 @@ interface OpenDashboardPopupWaterTankOptions {
1729
1729
  deviceType?: string;
1730
1730
  label?: string;
1731
1731
  currentLevel?: number;
1732
+ currentLevelClamped?: number;
1733
+ waterLevel?: number | null;
1734
+ waterPercentage?: number | null;
1732
1735
  slaveId?: string | number;
1733
1736
  centralId?: string;
1734
1737
  ingestionId?: string;
1735
1738
  telemetryKeys?: string[];
1739
+ displayKey?: 'water_level' | 'water_percentage';
1736
1740
  aggregation?: 'NONE' | 'MIN' | 'MAX' | 'AVG' | 'SUM' | 'COUNT';
1737
1741
  limit?: number;
1738
1742
  tbApiHost?: string;
package/dist/index.js CHANGED
@@ -21959,12 +21959,13 @@ var WaterTankModal = class {
21959
21959
  * Build context object for callbacks
21960
21960
  */
21961
21961
  buildContext(options) {
21962
+ const displayLevel = options.currentLevelClamped ?? options.currentLevel ?? 0;
21962
21963
  return {
21963
21964
  device: {
21964
21965
  id: options.deviceId,
21965
21966
  label: options.label || options.deviceId,
21966
21967
  type: options.deviceType,
21967
- currentLevel: options.currentLevel
21968
+ currentLevel: displayLevel
21968
21969
  },
21969
21970
  metadata: {
21970
21971
  slaveId: options.slaveId,
@@ -22054,16 +22055,25 @@ var WaterTankModal = class {
22054
22055
  }
22055
22056
  /**
22056
22057
  * Transform raw ThingsBoard response to our data points
22058
+ * RFC-0107: Support displayKey option to choose between water_level or water_percentage
22057
22059
  */
22058
22060
  transformTelemetryData(rawData, keys) {
22059
22061
  const allPoints = [];
22060
- for (const key of keys) {
22062
+ const displayKey = this.options.displayKey || "water_percentage";
22063
+ const prioritizedKeys = displayKey && rawData[displayKey] ? [displayKey, ...keys.filter((k) => k !== displayKey)] : keys;
22064
+ for (const key of prioritizedKeys) {
22061
22065
  if (rawData[key] && Array.isArray(rawData[key])) {
22062
- const keyPoints = rawData[key].map((point) => ({
22063
- ts: point.ts,
22064
- value: typeof point.value === "string" ? parseFloat(point.value) : point.value,
22065
- key
22066
- }));
22066
+ const keyPoints = rawData[key].map((point) => {
22067
+ let value = typeof point.value === "string" ? parseFloat(point.value) : point.value;
22068
+ if (key === "water_percentage" && value <= 1.5) {
22069
+ value = value * 100;
22070
+ }
22071
+ return {
22072
+ ts: point.ts,
22073
+ value,
22074
+ key
22075
+ };
22076
+ });
22067
22077
  allPoints.push(...keyPoints);
22068
22078
  }
22069
22079
  }
@@ -22076,15 +22086,18 @@ var WaterTankModal = class {
22076
22086
  uniquePoints.push(point);
22077
22087
  }
22078
22088
  }
22089
+ console.log(`[WaterTankModal] Transformed ${uniquePoints.length} points, displayKey: ${displayKey}`);
22079
22090
  return uniquePoints;
22080
22091
  }
22081
22092
  /**
22082
22093
  * Calculate summary statistics from telemetry data
22094
+ * RFC-0107: Use clamped level for display
22083
22095
  */
22084
22096
  calculateSummary(telemetry) {
22097
+ const displayLevel = this.options.currentLevelClamped ?? this.options.currentLevel ?? 0;
22085
22098
  if (telemetry.length === 0) {
22086
22099
  return {
22087
- currentLevel: this.options.currentLevel,
22100
+ currentLevel: displayLevel,
22088
22101
  avgLevel: 0,
22089
22102
  minLevel: 0,
22090
22103
  maxLevel: 0,
@@ -21773,12 +21773,13 @@
21773
21773
  * Build context object for callbacks
21774
21774
  */
21775
21775
  buildContext(options) {
21776
+ const displayLevel = options.currentLevelClamped ?? options.currentLevel ?? 0;
21776
21777
  return {
21777
21778
  device: {
21778
21779
  id: options.deviceId,
21779
21780
  label: options.label || options.deviceId,
21780
21781
  type: options.deviceType,
21781
- currentLevel: options.currentLevel
21782
+ currentLevel: displayLevel
21782
21783
  },
21783
21784
  metadata: {
21784
21785
  slaveId: options.slaveId,
@@ -21868,16 +21869,25 @@
21868
21869
  }
21869
21870
  /**
21870
21871
  * Transform raw ThingsBoard response to our data points
21872
+ * RFC-0107: Support displayKey option to choose between water_level or water_percentage
21871
21873
  */
21872
21874
  transformTelemetryData(rawData, keys) {
21873
21875
  const allPoints = [];
21874
- for (const key of keys) {
21876
+ const displayKey = this.options.displayKey || "water_percentage";
21877
+ const prioritizedKeys = rawData[displayKey] ? [displayKey, ...keys.filter((k) => k !== displayKey)] : keys;
21878
+ for (const key of prioritizedKeys) {
21875
21879
  if (rawData[key] && Array.isArray(rawData[key])) {
21876
- const keyPoints = rawData[key].map((point) => ({
21877
- ts: point.ts,
21878
- value: typeof point.value === "string" ? parseFloat(point.value) : point.value,
21879
- key
21880
- }));
21880
+ const keyPoints = rawData[key].map((point) => {
21881
+ let value = typeof point.value === "string" ? parseFloat(point.value) : point.value;
21882
+ if (key === "water_percentage" && value <= 1.5) {
21883
+ value = value * 100;
21884
+ }
21885
+ return {
21886
+ ts: point.ts,
21887
+ value,
21888
+ key
21889
+ };
21890
+ });
21881
21891
  allPoints.push(...keyPoints);
21882
21892
  }
21883
21893
  }
@@ -21890,15 +21900,18 @@
21890
21900
  uniquePoints.push(point);
21891
21901
  }
21892
21902
  }
21903
+ console.log(`[WaterTankModal] Transformed ${uniquePoints.length} points, displayKey: ${displayKey}`);
21893
21904
  return uniquePoints;
21894
21905
  }
21895
21906
  /**
21896
21907
  * Calculate summary statistics from telemetry data
21908
+ * RFC-0107: Use clamped level for display
21897
21909
  */
21898
21910
  calculateSummary(telemetry) {
21911
+ const displayLevel = this.options.currentLevelClamped ?? this.options.currentLevel ?? 0;
21899
21912
  if (telemetry.length === 0) {
21900
21913
  return {
21901
- currentLevel: this.options.currentLevel,
21914
+ currentLevel: displayLevel,
21902
21915
  avgLevel: 0,
21903
21916
  minLevel: 0,
21904
21917
  maxLevel: 0,