myio-js-library 0.1.584 → 0.1.585

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
@@ -989,7 +989,7 @@ module.exports = __toCommonJS(src_exports);
989
989
  // package.json
990
990
  var package_default = {
991
991
  name: "myio-js-library",
992
- version: "0.1.584",
992
+ version: "0.1.585",
993
993
  description: "A clean, standalone JS SDK for MYIO projects",
994
994
  license: "MIT",
995
995
  repository: "github:gh-myio/myio-js-library",
@@ -29465,6 +29465,42 @@ var TELEMETRY_CONFIG = {
29465
29465
  // Temperature
29466
29466
  temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 }
29467
29467
  };
29468
+ var CURRENT_KEYS_MA = /* @__PURE__ */ new Set(["total_current", "current", "current_a", "current_b", "current_c"]);
29469
+ var POWER_FACTOR_KEYS_255 = /* @__PURE__ */ new Set(["fp_a", "fp_b", "fp_c", "powerFactor"]);
29470
+ function normalizeTelemetryValue(key, raw) {
29471
+ const v = Number(raw) || 0;
29472
+ if (CURRENT_KEYS_MA.has(key)) return v / 1e3;
29473
+ if (POWER_FACTOR_KEYS_255.has(key)) return v / 255;
29474
+ return v;
29475
+ }
29476
+ function scaleWatts(value, decimals) {
29477
+ const abs = Math.abs(value);
29478
+ if (abs >= 1e6) return `${(value / 1e6).toFixed(decimals)} MW`;
29479
+ if (abs >= 1e3) return `${(value / 1e3).toFixed(decimals)} kW`;
29480
+ return `${value.toFixed(0)} W`;
29481
+ }
29482
+ function formatTelemetryValue(key, value) {
29483
+ const config2 = TELEMETRY_CONFIG[key];
29484
+ if (!config2) return value.toFixed(2);
29485
+ if (config2.unit === "W") return scaleWatts(value, 2);
29486
+ return `${value.toFixed(config2.decimals)} ${config2.unit}`;
29487
+ }
29488
+ function formatAxisTick(unit, value) {
29489
+ if (unit === "W") {
29490
+ const n = Number(value);
29491
+ if (Math.abs(n) >= 1e3) return scaleWatts(n, 1);
29492
+ return `${value} W`;
29493
+ }
29494
+ return `${value}${unit ? " " + unit : ""}`;
29495
+ }
29496
+ function formatPeakValue(key, value) {
29497
+ const cfg = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "", decimals: 2 };
29498
+ if (cfg.unit === "W") return formatPower(value, 3);
29499
+ return `${value.toLocaleString("pt-BR", {
29500
+ minimumFractionDigits: cfg.decimals ?? 2,
29501
+ maximumFractionDigits: cfg.decimals ?? 2
29502
+ })} ${cfg.unit}`;
29503
+ }
29468
29504
  var PHASE_SHORT_LABEL = {
29469
29505
  consumption: "Total",
29470
29506
  power: "Total",
@@ -31638,11 +31674,7 @@ async function openRealTimeTelemetryModal(params) {
31638
31674
  });
31639
31675
  }
31640
31676
  function normalizeRealtimeValue(key, raw) {
31641
- if (key === "total_current" || key === "current" || key === "current_a" || key === "current_b" || key === "current_c") {
31642
- return raw / 1e3;
31643
- }
31644
- if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") return raw / 255;
31645
- return raw;
31677
+ return normalizeTelemetryValue(key, raw);
31646
31678
  }
31647
31679
  function fillAggregatedGaps(returned, startTs, endTs, intervalMs, seedY) {
31648
31680
  const byBucket = /* @__PURE__ */ new Map();
@@ -31795,13 +31827,7 @@ async function openRealTimeTelemetryModal(params) {
31795
31827
  const data = await fetchPeriodTelemetry(periodStartISO, periodEndISO);
31796
31828
  periodHistory.clear();
31797
31829
  periodLastKnown.clear();
31798
- const toPeriodY = (key, raw) => {
31799
- let y = raw ?? 0;
31800
- if (key === "total_current" || key === "current") y = y / 1e3;
31801
- if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") y = y / 255;
31802
- if (POWER_KEYS.has(key)) y = y / 1e3;
31803
- return y;
31804
- };
31830
+ const toPeriodY = (key, raw) => normalizeTelemetryValue(key, raw);
31805
31831
  const fillGaps = selectedAgg !== "NONE";
31806
31832
  const periodStartTs = new Date(periodStartISO).getTime();
31807
31833
  const periodEndTs = new Date(periodEndISO).getTime();
@@ -31851,10 +31877,7 @@ async function openRealTimeTelemetryModal(params) {
31851
31877
  minute: "2-digit"
31852
31878
  }
31853
31879
  ) : "";
31854
- const formattedValue = cfg.unit === "W" ? formatPower(peakPoint.y, 3) : `${peakPoint.y.toLocaleString("pt-BR", {
31855
- minimumFractionDigits: cfg.decimals ?? 2,
31856
- maximumFractionDigits: cfg.decimals ?? 2
31857
- })} ${cfg.unit}`;
31880
+ const formattedValue = formatPeakValue(peakKey, peakPoint.y);
31858
31881
  peakSummaryEl.textContent = `M\xE1xima: ${formattedValue} (${cfg.label}) em ${when}`;
31859
31882
  peakSummaryEl.style.display = "block";
31860
31883
  } else {
@@ -31879,13 +31902,7 @@ async function openRealTimeTelemetryModal(params) {
31879
31902
  if (!telemetryData || telemetryData.length === 0) continue;
31880
31903
  const latest = telemetryData[0];
31881
31904
  const config2 = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "\u{1F4CA}", decimals: 2 };
31882
- let numValue = Number(latest.value) || 0;
31883
- if (key === "total_current" || key === "current" || key === "current_a" || key === "current_b" || key === "current_c") {
31884
- numValue = numValue / 1e3;
31885
- }
31886
- if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") {
31887
- numValue = numValue / 255;
31888
- }
31905
+ const numValue = normalizeTelemetryValue(key, latest.value);
31889
31906
  const formattedNum = numValue.toFixed(config2.decimals);
31890
31907
  const displayUnit = config2.unit === "fp" ? "" : config2.unit;
31891
31908
  const formatted = displayUnit ? `${formattedNum} ${displayUnit}` : formattedNum;
@@ -32116,15 +32133,7 @@ async function openRealTimeTelemetryModal(params) {
32116
32133
  }
32117
32134
  }
32118
32135
  function getFormattedValue(key, value) {
32119
- const config2 = TELEMETRY_CONFIG[key];
32120
- if (!config2) return value.toFixed(2);
32121
- if (key === "consumption" || key === "power") {
32122
- if (value >= 1e3) {
32123
- return `${(value / 1e3).toFixed(2)} kW`;
32124
- }
32125
- return `${value.toFixed(0)} W`;
32126
- }
32127
- return `${value.toFixed(config2.decimals)} ${config2.unit}`;
32136
+ return formatTelemetryValue(key, value);
32128
32137
  }
32129
32138
  function hexRgba(hex, alpha) {
32130
32139
  const r = parseInt(hex.slice(1, 3), 16);
@@ -32154,11 +32163,7 @@ async function openRealTimeTelemetryModal(params) {
32154
32163
  const rightAxisColor = rightAxisKey ? KEY_COLORS[rightAxisKey] || "#555" : "#555";
32155
32164
  function makeTickCallback(unit) {
32156
32165
  return function(value) {
32157
- if (unit === "W") {
32158
- if (value >= 1e3) return `${(value / 1e3).toFixed(1)} kW`;
32159
- return `${value} W`;
32160
- }
32161
- return `${value}${unit ? " " + unit : ""}`;
32166
+ return formatAxisTick(unit, value);
32162
32167
  };
32163
32168
  }
32164
32169
  const datasets = selectedChartKeys.map((key) => {
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  // package.json
11
11
  var package_default = {
12
12
  name: "myio-js-library",
13
- version: "0.1.584",
13
+ version: "0.1.585",
14
14
  description: "A clean, standalone JS SDK for MYIO projects",
15
15
  license: "MIT",
16
16
  repository: "github:gh-myio/myio-js-library",
@@ -27761,6 +27761,42 @@ var TELEMETRY_CONFIG = {
27761
27761
  // Temperature
27762
27762
  temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 }
27763
27763
  };
27764
+ var CURRENT_KEYS_MA = /* @__PURE__ */ new Set(["total_current", "current", "current_a", "current_b", "current_c"]);
27765
+ var POWER_FACTOR_KEYS_255 = /* @__PURE__ */ new Set(["fp_a", "fp_b", "fp_c", "powerFactor"]);
27766
+ function normalizeTelemetryValue(key, raw) {
27767
+ const v = Number(raw) || 0;
27768
+ if (CURRENT_KEYS_MA.has(key)) return v / 1e3;
27769
+ if (POWER_FACTOR_KEYS_255.has(key)) return v / 255;
27770
+ return v;
27771
+ }
27772
+ function scaleWatts(value, decimals) {
27773
+ const abs = Math.abs(value);
27774
+ if (abs >= 1e6) return `${(value / 1e6).toFixed(decimals)} MW`;
27775
+ if (abs >= 1e3) return `${(value / 1e3).toFixed(decimals)} kW`;
27776
+ return `${value.toFixed(0)} W`;
27777
+ }
27778
+ function formatTelemetryValue(key, value) {
27779
+ const config = TELEMETRY_CONFIG[key];
27780
+ if (!config) return value.toFixed(2);
27781
+ if (config.unit === "W") return scaleWatts(value, 2);
27782
+ return `${value.toFixed(config.decimals)} ${config.unit}`;
27783
+ }
27784
+ function formatAxisTick(unit, value) {
27785
+ if (unit === "W") {
27786
+ const n = Number(value);
27787
+ if (Math.abs(n) >= 1e3) return scaleWatts(n, 1);
27788
+ return `${value} W`;
27789
+ }
27790
+ return `${value}${unit ? " " + unit : ""}`;
27791
+ }
27792
+ function formatPeakValue(key, value) {
27793
+ const cfg = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "", decimals: 2 };
27794
+ if (cfg.unit === "W") return formatPower(value, 3);
27795
+ return `${value.toLocaleString("pt-BR", {
27796
+ minimumFractionDigits: cfg.decimals ?? 2,
27797
+ maximumFractionDigits: cfg.decimals ?? 2
27798
+ })} ${cfg.unit}`;
27799
+ }
27764
27800
  var PHASE_SHORT_LABEL = {
27765
27801
  consumption: "Total",
27766
27802
  power: "Total",
@@ -29934,11 +29970,7 @@ async function openRealTimeTelemetryModal(params) {
29934
29970
  });
29935
29971
  }
29936
29972
  function normalizeRealtimeValue(key, raw) {
29937
- if (key === "total_current" || key === "current" || key === "current_a" || key === "current_b" || key === "current_c") {
29938
- return raw / 1e3;
29939
- }
29940
- if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") return raw / 255;
29941
- return raw;
29973
+ return normalizeTelemetryValue(key, raw);
29942
29974
  }
29943
29975
  function fillAggregatedGaps(returned, startTs, endTs, intervalMs, seedY) {
29944
29976
  const byBucket = /* @__PURE__ */ new Map();
@@ -30091,13 +30123,7 @@ async function openRealTimeTelemetryModal(params) {
30091
30123
  const data = await fetchPeriodTelemetry(periodStartISO, periodEndISO);
30092
30124
  periodHistory.clear();
30093
30125
  periodLastKnown.clear();
30094
- const toPeriodY = (key, raw) => {
30095
- let y = raw ?? 0;
30096
- if (key === "total_current" || key === "current") y = y / 1e3;
30097
- if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") y = y / 255;
30098
- if (POWER_KEYS.has(key)) y = y / 1e3;
30099
- return y;
30100
- };
30126
+ const toPeriodY = (key, raw) => normalizeTelemetryValue(key, raw);
30101
30127
  const fillGaps = selectedAgg !== "NONE";
30102
30128
  const periodStartTs = new Date(periodStartISO).getTime();
30103
30129
  const periodEndTs = new Date(periodEndISO).getTime();
@@ -30147,10 +30173,7 @@ async function openRealTimeTelemetryModal(params) {
30147
30173
  minute: "2-digit"
30148
30174
  }
30149
30175
  ) : "";
30150
- const formattedValue = cfg.unit === "W" ? formatPower(peakPoint.y, 3) : `${peakPoint.y.toLocaleString("pt-BR", {
30151
- minimumFractionDigits: cfg.decimals ?? 2,
30152
- maximumFractionDigits: cfg.decimals ?? 2
30153
- })} ${cfg.unit}`;
30176
+ const formattedValue = formatPeakValue(peakKey, peakPoint.y);
30154
30177
  peakSummaryEl.textContent = `M\xE1xima: ${formattedValue} (${cfg.label}) em ${when}`;
30155
30178
  peakSummaryEl.style.display = "block";
30156
30179
  } else {
@@ -30175,13 +30198,7 @@ async function openRealTimeTelemetryModal(params) {
30175
30198
  if (!telemetryData || telemetryData.length === 0) continue;
30176
30199
  const latest = telemetryData[0];
30177
30200
  const config = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "\u{1F4CA}", decimals: 2 };
30178
- let numValue = Number(latest.value) || 0;
30179
- if (key === "total_current" || key === "current" || key === "current_a" || key === "current_b" || key === "current_c") {
30180
- numValue = numValue / 1e3;
30181
- }
30182
- if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") {
30183
- numValue = numValue / 255;
30184
- }
30201
+ const numValue = normalizeTelemetryValue(key, latest.value);
30185
30202
  const formattedNum = numValue.toFixed(config.decimals);
30186
30203
  const displayUnit = config.unit === "fp" ? "" : config.unit;
30187
30204
  const formatted = displayUnit ? `${formattedNum} ${displayUnit}` : formattedNum;
@@ -30412,15 +30429,7 @@ async function openRealTimeTelemetryModal(params) {
30412
30429
  }
30413
30430
  }
30414
30431
  function getFormattedValue(key, value) {
30415
- const config = TELEMETRY_CONFIG[key];
30416
- if (!config) return value.toFixed(2);
30417
- if (key === "consumption" || key === "power") {
30418
- if (value >= 1e3) {
30419
- return `${(value / 1e3).toFixed(2)} kW`;
30420
- }
30421
- return `${value.toFixed(0)} W`;
30422
- }
30423
- return `${value.toFixed(config.decimals)} ${config.unit}`;
30432
+ return formatTelemetryValue(key, value);
30424
30433
  }
30425
30434
  function hexRgba(hex, alpha) {
30426
30435
  const r = parseInt(hex.slice(1, 3), 16);
@@ -30450,11 +30459,7 @@ async function openRealTimeTelemetryModal(params) {
30450
30459
  const rightAxisColor = rightAxisKey ? KEY_COLORS[rightAxisKey] || "#555" : "#555";
30451
30460
  function makeTickCallback(unit) {
30452
30461
  return function(value) {
30453
- if (unit === "W") {
30454
- if (value >= 1e3) return `${(value / 1e3).toFixed(1)} kW`;
30455
- return `${value} W`;
30456
- }
30457
- return `${value}${unit ? " " + unit : ""}`;
30462
+ return formatAxisTick(unit, value);
30458
30463
  };
30459
30464
  }
30460
30465
  const datasets = selectedChartKeys.map((key) => {
@@ -5524,7 +5524,7 @@
5524
5524
 
5525
5525
  // package.json
5526
5526
  var package_default = {
5527
- version: "0.1.584"};
5527
+ version: "0.1.585"};
5528
5528
 
5529
5529
  // src/utils/format/energy.ts
5530
5530
  function formatPower(value, decimals = 2) {
@@ -33156,6 +33156,42 @@
33156
33156
  // Temperature
33157
33157
  temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 }
33158
33158
  };
33159
+ var CURRENT_KEYS_MA = /* @__PURE__ */ new Set(["total_current", "current", "current_a", "current_b", "current_c"]);
33160
+ var POWER_FACTOR_KEYS_255 = /* @__PURE__ */ new Set(["fp_a", "fp_b", "fp_c", "powerFactor"]);
33161
+ function normalizeTelemetryValue(key, raw) {
33162
+ const v = Number(raw) || 0;
33163
+ if (CURRENT_KEYS_MA.has(key)) return v / 1e3;
33164
+ if (POWER_FACTOR_KEYS_255.has(key)) return v / 255;
33165
+ return v;
33166
+ }
33167
+ function scaleWatts(value, decimals) {
33168
+ const abs = Math.abs(value);
33169
+ if (abs >= 1e6) return `${(value / 1e6).toFixed(decimals)} MW`;
33170
+ if (abs >= 1e3) return `${(value / 1e3).toFixed(decimals)} kW`;
33171
+ return `${value.toFixed(0)} W`;
33172
+ }
33173
+ function formatTelemetryValue(key, value) {
33174
+ const config = TELEMETRY_CONFIG[key];
33175
+ if (!config) return value.toFixed(2);
33176
+ if (config.unit === "W") return scaleWatts(value, 2);
33177
+ return `${value.toFixed(config.decimals)} ${config.unit}`;
33178
+ }
33179
+ function formatAxisTick(unit, value) {
33180
+ if (unit === "W") {
33181
+ const n = Number(value);
33182
+ if (Math.abs(n) >= 1e3) return scaleWatts(n, 1);
33183
+ return `${value} W`;
33184
+ }
33185
+ return `${value}${unit ? " " + unit : ""}`;
33186
+ }
33187
+ function formatPeakValue(key, value) {
33188
+ const cfg = TELEMETRY_CONFIG[key] || { unit: "", decimals: 2 };
33189
+ if (cfg.unit === "W") return formatPower(value, 3);
33190
+ return `${value.toLocaleString("pt-BR", {
33191
+ minimumFractionDigits: cfg.decimals ?? 2,
33192
+ maximumFractionDigits: cfg.decimals ?? 2
33193
+ })} ${cfg.unit}`;
33194
+ }
33159
33195
  var PHASE_SHORT_LABEL = {
33160
33196
  consumption: "Total",
33161
33197
  power: "Total",
@@ -35329,11 +35365,7 @@
35329
35365
  });
35330
35366
  }
35331
35367
  function normalizeRealtimeValue(key, raw) {
35332
- if (key === "total_current" || key === "current" || key === "current_a" || key === "current_b" || key === "current_c") {
35333
- return raw / 1e3;
35334
- }
35335
- if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") return raw / 255;
35336
- return raw;
35368
+ return normalizeTelemetryValue(key, raw);
35337
35369
  }
35338
35370
  function fillAggregatedGaps(returned, startTs, endTs, intervalMs, seedY) {
35339
35371
  const byBucket = /* @__PURE__ */ new Map();
@@ -35486,13 +35518,7 @@
35486
35518
  const data = await fetchPeriodTelemetry(periodStartISO, periodEndISO);
35487
35519
  periodHistory.clear();
35488
35520
  periodLastKnown.clear();
35489
- const toPeriodY = (key, raw) => {
35490
- let y = raw ?? 0;
35491
- if (key === "total_current" || key === "current") y = y / 1e3;
35492
- if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") y = y / 255;
35493
- if (POWER_KEYS.has(key)) y = y / 1e3;
35494
- return y;
35495
- };
35521
+ const toPeriodY = (key, raw) => normalizeTelemetryValue(key, raw);
35496
35522
  const fillGaps = selectedAgg !== "NONE";
35497
35523
  const periodStartTs = new Date(periodStartISO).getTime();
35498
35524
  const periodEndTs = new Date(periodEndISO).getTime();
@@ -35542,10 +35568,7 @@
35542
35568
  minute: "2-digit"
35543
35569
  }
35544
35570
  ) : "";
35545
- const formattedValue = cfg.unit === "W" ? formatPower(peakPoint.y, 3) : `${peakPoint.y.toLocaleString("pt-BR", {
35546
- minimumFractionDigits: cfg.decimals ?? 2,
35547
- maximumFractionDigits: cfg.decimals ?? 2
35548
- })} ${cfg.unit}`;
35571
+ const formattedValue = formatPeakValue(peakKey, peakPoint.y);
35549
35572
  peakSummaryEl.textContent = `M\xE1xima: ${formattedValue} (${cfg.label}) em ${when}`;
35550
35573
  peakSummaryEl.style.display = "block";
35551
35574
  } else {
@@ -35570,13 +35593,7 @@
35570
35593
  if (!telemetryData || telemetryData.length === 0) continue;
35571
35594
  const latest = telemetryData[0];
35572
35595
  const config = TELEMETRY_CONFIG[key] || { label: key, unit: "", icon: "\u{1F4CA}", decimals: 2 };
35573
- let numValue = Number(latest.value) || 0;
35574
- if (key === "total_current" || key === "current" || key === "current_a" || key === "current_b" || key === "current_c") {
35575
- numValue = numValue / 1e3;
35576
- }
35577
- if (key === "fp_a" || key === "fp_b" || key === "fp_c" || key === "powerFactor") {
35578
- numValue = numValue / 255;
35579
- }
35596
+ const numValue = normalizeTelemetryValue(key, latest.value);
35580
35597
  const formattedNum = numValue.toFixed(config.decimals);
35581
35598
  const displayUnit = config.unit === "fp" ? "" : config.unit;
35582
35599
  const formatted = displayUnit ? `${formattedNum} ${displayUnit}` : formattedNum;
@@ -35807,15 +35824,7 @@
35807
35824
  }
35808
35825
  }
35809
35826
  function getFormattedValue(key, value) {
35810
- const config = TELEMETRY_CONFIG[key];
35811
- if (!config) return value.toFixed(2);
35812
- if (key === "consumption" || key === "power") {
35813
- if (value >= 1e3) {
35814
- return `${(value / 1e3).toFixed(2)} kW`;
35815
- }
35816
- return `${value.toFixed(0)} W`;
35817
- }
35818
- return `${value.toFixed(config.decimals)} ${config.unit}`;
35827
+ return formatTelemetryValue(key, value);
35819
35828
  }
35820
35829
  function hexRgba(hex, alpha) {
35821
35830
  const r = parseInt(hex.slice(1, 3), 16);
@@ -35845,11 +35854,7 @@
35845
35854
  const rightAxisColor = rightAxisKey ? KEY_COLORS[rightAxisKey] || "#555" : "#555";
35846
35855
  function makeTickCallback(unit) {
35847
35856
  return function(value) {
35848
- if (unit === "W") {
35849
- if (value >= 1e3) return `${(value / 1e3).toFixed(1)} kW`;
35850
- return `${value} W`;
35851
- }
35852
- return `${value}${unit ? " " + unit : ""}`;
35857
+ return formatAxisTick(unit, value);
35853
35858
  };
35854
35859
  }
35855
35860
  const datasets = selectedChartKeys.map((key) => {