myio-js-library 0.1.136 → 0.1.137

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
@@ -7081,8 +7081,8 @@ var TELEMETRY_CONFIG = {
7081
7081
  total_current: { label: "Corrente Total", unit: "A", icon: "\u{1F50C}", decimals: 2 },
7082
7082
  current: { label: "Corrente", unit: "A", icon: "\u{1F50C}", decimals: 2 },
7083
7083
  // Power and Energy
7084
- consumption: { label: "Consumo", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
7085
- power: { label: "Pot\xEAncia", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
7084
+ consumption: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
7085
+ power: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
7086
7086
  energy: { label: "Energia", unit: "kWh", icon: "\u{1F4CA}", decimals: 1 },
7087
7087
  activePower: { label: "Pot\xEAncia Ativa", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
7088
7088
  reactivePower: { label: "Pot\xEAncia Reativa", unit: "kVAr", icon: "\u{1F504}", decimals: 2 },
@@ -7138,7 +7138,9 @@ async function openRealTimeTelemetryModal(params) {
7138
7138
  let refreshIntervalId = null;
7139
7139
  let isPaused = false;
7140
7140
  let telemetryHistory = /* @__PURE__ */ new Map();
7141
+ let lastKnownValues = /* @__PURE__ */ new Map();
7141
7142
  let chart = null;
7143
+ let selectedChartKey = "consumption";
7142
7144
  const overlay = document.createElement("div");
7143
7145
  overlay.className = "myio-realtime-telemetry-overlay";
7144
7146
  overlay.innerHTML = `
@@ -7299,7 +7301,27 @@ async function openRealTimeTelemetryModal(params) {
7299
7301
  }
7300
7302
 
7301
7303
  .myio-telemetry-chart {
7302
- height: 200px;
7304
+ height: 250px;
7305
+ }
7306
+
7307
+ .myio-telemetry-selector {
7308
+ padding: 8px 12px;
7309
+ border: 1px solid #ddd;
7310
+ border-radius: 6px;
7311
+ font-size: 14px;
7312
+ background: white;
7313
+ cursor: pointer;
7314
+ transition: border-color 0.2s;
7315
+ }
7316
+
7317
+ .myio-telemetry-selector:hover {
7318
+ border-color: #667eea;
7319
+ }
7320
+
7321
+ .myio-telemetry-selector:focus {
7322
+ outline: none;
7323
+ border-color: #667eea;
7324
+ box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
7303
7325
  }
7304
7326
 
7305
7327
  .myio-realtime-telemetry-footer {
@@ -7409,7 +7431,16 @@ async function openRealTimeTelemetryModal(params) {
7409
7431
  <div class="myio-telemetry-cards-grid" id="telemetry-cards"></div>
7410
7432
 
7411
7433
  <div class="myio-telemetry-chart-container" id="chart-container" style="display: none;">
7412
- <h3 class="myio-telemetry-chart-title" id="chart-title">Pot\xEAncia (\xFAltimos 5 min)</h3>
7434
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
7435
+ <h3 class="myio-telemetry-chart-title" id="chart-title" style="margin: 0;">Hist\xF3rico de Telemetria</h3>
7436
+ <select id="chart-key-selector" class="myio-telemetry-selector">
7437
+ <option value="consumption">Pot\xEAncia</option>
7438
+ <option value="total_current">Corrente Total</option>
7439
+ <option value="voltage_a">Tens\xE3o Fase A</option>
7440
+ <option value="voltage_b">Tens\xE3o Fase B</option>
7441
+ <option value="voltage_c">Tens\xE3o Fase C</option>
7442
+ </select>
7443
+ </div>
7413
7444
  <canvas class="myio-telemetry-chart" id="telemetry-chart"></canvas>
7414
7445
  </div>
7415
7446
  </div>
@@ -7451,6 +7482,7 @@ async function openRealTimeTelemetryModal(params) {
7451
7482
  const telemetryCards = document.getElementById("telemetry-cards");
7452
7483
  const chartContainer = document.getElementById("chart-container");
7453
7484
  const chartCanvas = document.getElementById("telemetry-chart");
7485
+ const chartKeySelector = document.getElementById("chart-key-selector");
7454
7486
  const statusIndicator = document.getElementById("status-indicator");
7455
7487
  const statusText = document.getElementById("status-text");
7456
7488
  const lastUpdateText = document.getElementById("last-update-text");
@@ -7542,16 +7574,42 @@ async function openRealTimeTelemetryModal(params) {
7542
7574
  }
7543
7575
  const history = telemetryHistory.get(tel.key);
7544
7576
  history.push({ x: now, y: tel.value });
7577
+ lastKnownValues.set(tel.key, tel.value);
7545
7578
  if (history.length > historyPoints) {
7546
7579
  history.shift();
7547
7580
  }
7548
7581
  }
7549
- if (telemetryHistory.has("power") && chart) {
7550
- const powerHistory = telemetryHistory.get("power");
7551
- chart.data.datasets[0].data = powerHistory;
7582
+ for (const key of telemetryKeys) {
7583
+ const receivedKeys = values.map((v) => v.key);
7584
+ if (!receivedKeys.includes(key) && lastKnownValues.has(key)) {
7585
+ if (!telemetryHistory.has(key)) {
7586
+ telemetryHistory.set(key, []);
7587
+ }
7588
+ const history = telemetryHistory.get(key);
7589
+ const lastValue = lastKnownValues.get(key);
7590
+ history.push({ x: now, y: lastValue });
7591
+ if (history.length > historyPoints) {
7592
+ history.shift();
7593
+ }
7594
+ }
7595
+ }
7596
+ if (telemetryHistory.has(selectedChartKey) && chart) {
7597
+ const selectedHistory = telemetryHistory.get(selectedChartKey);
7598
+ chart.data.datasets[0].data = selectedHistory;
7552
7599
  chart.update("none");
7553
7600
  }
7554
7601
  }
7602
+ function getFormattedValue(key, value) {
7603
+ const config = TELEMETRY_CONFIG[key];
7604
+ if (!config) return value.toFixed(2);
7605
+ if (key === "consumption" || key === "power") {
7606
+ if (value >= 1e3) {
7607
+ return `${(value / 1e3).toFixed(2)} kW`;
7608
+ }
7609
+ return `${value.toFixed(0)} W`;
7610
+ }
7611
+ return `${value.toFixed(config.decimals)} ${config.unit}`;
7612
+ }
7555
7613
  function initializeChart() {
7556
7614
  const Chart = window.Chart;
7557
7615
  if (!Chart) {
@@ -7559,23 +7617,26 @@ async function openRealTimeTelemetryModal(params) {
7559
7617
  return;
7560
7618
  }
7561
7619
  chartContainer.style.display = "block";
7620
+ const config = TELEMETRY_CONFIG[selectedChartKey] || { label: selectedChartKey, unit: "" };
7562
7621
  chart = new Chart(chartCanvas, {
7563
7622
  type: "line",
7564
7623
  data: {
7565
7624
  datasets: [{
7566
- label: "Pot\xEAncia",
7625
+ label: config.label,
7567
7626
  data: [],
7568
7627
  borderColor: "#667eea",
7569
7628
  backgroundColor: "rgba(102, 126, 234, 0.1)",
7570
7629
  borderWidth: 2,
7571
7630
  fill: true,
7572
7631
  tension: 0.4,
7573
- pointRadius: 0
7632
+ pointRadius: 3,
7633
+ pointHoverRadius: 5
7574
7634
  }]
7575
7635
  },
7576
7636
  options: {
7577
7637
  responsive: true,
7578
7638
  maintainAspectRatio: false,
7639
+ animation: false,
7579
7640
  plugins: {
7580
7641
  legend: { display: false },
7581
7642
  tooltip: {
@@ -7583,10 +7644,18 @@ async function openRealTimeTelemetryModal(params) {
7583
7644
  title: function(context) {
7584
7645
  const timestamp = context[0].parsed.x;
7585
7646
  const date = new Date(timestamp);
7586
- return date.toLocaleTimeString(locale);
7647
+ return date.toLocaleString(locale, {
7648
+ day: "2-digit",
7649
+ month: "2-digit",
7650
+ year: "numeric",
7651
+ hour: "2-digit",
7652
+ minute: "2-digit",
7653
+ second: "2-digit"
7654
+ });
7587
7655
  },
7588
7656
  label: function(context) {
7589
- return `${context.parsed.y.toFixed(2)} kW`;
7657
+ const value = context.parsed.y;
7658
+ return getFormattedValue(selectedChartKey, value);
7590
7659
  }
7591
7660
  }
7592
7661
  }
@@ -7595,23 +7664,57 @@ async function openRealTimeTelemetryModal(params) {
7595
7664
  x: {
7596
7665
  type: "linear",
7597
7666
  ticks: {
7667
+ maxRotation: 45,
7668
+ minRotation: 0,
7598
7669
  callback: function(value) {
7599
7670
  const date = new Date(value);
7600
- return date.toLocaleTimeString(locale, { hour: "2-digit", minute: "2-digit" });
7671
+ return date.toLocaleTimeString(locale, {
7672
+ hour: "2-digit",
7673
+ minute: "2-digit",
7674
+ second: "2-digit"
7675
+ });
7601
7676
  }
7677
+ },
7678
+ title: {
7679
+ display: true,
7680
+ text: "Hora"
7602
7681
  }
7603
7682
  },
7604
7683
  y: {
7605
7684
  beginAtZero: true,
7685
+ ticks: {
7686
+ callback: function(value) {
7687
+ if (selectedChartKey === "consumption" || selectedChartKey === "power") {
7688
+ if (value >= 1e3) {
7689
+ return `${(value / 1e3).toFixed(1)} kW`;
7690
+ }
7691
+ return `${value} W`;
7692
+ }
7693
+ return `${value} ${config.unit}`;
7694
+ }
7695
+ },
7606
7696
  title: {
7607
7697
  display: true,
7608
- text: "kW"
7698
+ text: selectedChartKey === "consumption" || selectedChartKey === "power" ? "W" : config.unit
7609
7699
  }
7610
7700
  }
7611
7701
  }
7612
7702
  }
7613
7703
  });
7614
7704
  }
7705
+ function updateChartKey(newKey) {
7706
+ selectedChartKey = newKey;
7707
+ if (chart) {
7708
+ chart.destroy();
7709
+ chart = null;
7710
+ }
7711
+ initializeChart();
7712
+ if (telemetryHistory.has(selectedChartKey)) {
7713
+ const selectedHistory = telemetryHistory.get(selectedChartKey);
7714
+ chart.data.datasets[0].data = selectedHistory;
7715
+ chart.update("none");
7716
+ }
7717
+ }
7615
7718
  async function refreshData() {
7616
7719
  try {
7617
7720
  const data = await fetchLatestTelemetry();
@@ -7623,9 +7726,7 @@ async function openRealTimeTelemetryModal(params) {
7623
7726
  if (loadingState.style.display !== "none") {
7624
7727
  loadingState.style.display = "none";
7625
7728
  telemetryContent.style.display = "block";
7626
- if (telemetryKeys.includes("power")) {
7627
- initializeChart();
7628
- }
7729
+ initializeChart();
7629
7730
  }
7630
7731
  } catch (error) {
7631
7732
  console.error("[RealTimeTelemetry] Error fetching data:", error);
@@ -7693,6 +7794,10 @@ async function openRealTimeTelemetryModal(params) {
7693
7794
  closeBtn.addEventListener("click", closeModal);
7694
7795
  pauseBtn.addEventListener("click", togglePause);
7695
7796
  exportBtn.addEventListener("click", exportToCSV2);
7797
+ chartKeySelector.addEventListener("change", (e) => {
7798
+ const newKey = e.target.value;
7799
+ updateChartKey(newKey);
7800
+ });
7696
7801
  overlay.addEventListener("click", (e) => {
7697
7802
  if (e.target === overlay) {
7698
7803
  closeModal();
package/dist/index.js CHANGED
@@ -6985,8 +6985,8 @@ var TELEMETRY_CONFIG = {
6985
6985
  total_current: { label: "Corrente Total", unit: "A", icon: "\u{1F50C}", decimals: 2 },
6986
6986
  current: { label: "Corrente", unit: "A", icon: "\u{1F50C}", decimals: 2 },
6987
6987
  // Power and Energy
6988
- consumption: { label: "Consumo", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
6989
- power: { label: "Pot\xEAncia", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
6988
+ consumption: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
6989
+ power: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
6990
6990
  energy: { label: "Energia", unit: "kWh", icon: "\u{1F4CA}", decimals: 1 },
6991
6991
  activePower: { label: "Pot\xEAncia Ativa", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
6992
6992
  reactivePower: { label: "Pot\xEAncia Reativa", unit: "kVAr", icon: "\u{1F504}", decimals: 2 },
@@ -7042,7 +7042,9 @@ async function openRealTimeTelemetryModal(params) {
7042
7042
  let refreshIntervalId = null;
7043
7043
  let isPaused = false;
7044
7044
  let telemetryHistory = /* @__PURE__ */ new Map();
7045
+ let lastKnownValues = /* @__PURE__ */ new Map();
7045
7046
  let chart = null;
7047
+ let selectedChartKey = "consumption";
7046
7048
  const overlay = document.createElement("div");
7047
7049
  overlay.className = "myio-realtime-telemetry-overlay";
7048
7050
  overlay.innerHTML = `
@@ -7203,7 +7205,27 @@ async function openRealTimeTelemetryModal(params) {
7203
7205
  }
7204
7206
 
7205
7207
  .myio-telemetry-chart {
7206
- height: 200px;
7208
+ height: 250px;
7209
+ }
7210
+
7211
+ .myio-telemetry-selector {
7212
+ padding: 8px 12px;
7213
+ border: 1px solid #ddd;
7214
+ border-radius: 6px;
7215
+ font-size: 14px;
7216
+ background: white;
7217
+ cursor: pointer;
7218
+ transition: border-color 0.2s;
7219
+ }
7220
+
7221
+ .myio-telemetry-selector:hover {
7222
+ border-color: #667eea;
7223
+ }
7224
+
7225
+ .myio-telemetry-selector:focus {
7226
+ outline: none;
7227
+ border-color: #667eea;
7228
+ box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
7207
7229
  }
7208
7230
 
7209
7231
  .myio-realtime-telemetry-footer {
@@ -7313,7 +7335,16 @@ async function openRealTimeTelemetryModal(params) {
7313
7335
  <div class="myio-telemetry-cards-grid" id="telemetry-cards"></div>
7314
7336
 
7315
7337
  <div class="myio-telemetry-chart-container" id="chart-container" style="display: none;">
7316
- <h3 class="myio-telemetry-chart-title" id="chart-title">Pot\xEAncia (\xFAltimos 5 min)</h3>
7338
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
7339
+ <h3 class="myio-telemetry-chart-title" id="chart-title" style="margin: 0;">Hist\xF3rico de Telemetria</h3>
7340
+ <select id="chart-key-selector" class="myio-telemetry-selector">
7341
+ <option value="consumption">Pot\xEAncia</option>
7342
+ <option value="total_current">Corrente Total</option>
7343
+ <option value="voltage_a">Tens\xE3o Fase A</option>
7344
+ <option value="voltage_b">Tens\xE3o Fase B</option>
7345
+ <option value="voltage_c">Tens\xE3o Fase C</option>
7346
+ </select>
7347
+ </div>
7317
7348
  <canvas class="myio-telemetry-chart" id="telemetry-chart"></canvas>
7318
7349
  </div>
7319
7350
  </div>
@@ -7355,6 +7386,7 @@ async function openRealTimeTelemetryModal(params) {
7355
7386
  const telemetryCards = document.getElementById("telemetry-cards");
7356
7387
  const chartContainer = document.getElementById("chart-container");
7357
7388
  const chartCanvas = document.getElementById("telemetry-chart");
7389
+ const chartKeySelector = document.getElementById("chart-key-selector");
7358
7390
  const statusIndicator = document.getElementById("status-indicator");
7359
7391
  const statusText = document.getElementById("status-text");
7360
7392
  const lastUpdateText = document.getElementById("last-update-text");
@@ -7446,16 +7478,42 @@ async function openRealTimeTelemetryModal(params) {
7446
7478
  }
7447
7479
  const history = telemetryHistory.get(tel.key);
7448
7480
  history.push({ x: now, y: tel.value });
7481
+ lastKnownValues.set(tel.key, tel.value);
7449
7482
  if (history.length > historyPoints) {
7450
7483
  history.shift();
7451
7484
  }
7452
7485
  }
7453
- if (telemetryHistory.has("power") && chart) {
7454
- const powerHistory = telemetryHistory.get("power");
7455
- chart.data.datasets[0].data = powerHistory;
7486
+ for (const key of telemetryKeys) {
7487
+ const receivedKeys = values.map((v) => v.key);
7488
+ if (!receivedKeys.includes(key) && lastKnownValues.has(key)) {
7489
+ if (!telemetryHistory.has(key)) {
7490
+ telemetryHistory.set(key, []);
7491
+ }
7492
+ const history = telemetryHistory.get(key);
7493
+ const lastValue = lastKnownValues.get(key);
7494
+ history.push({ x: now, y: lastValue });
7495
+ if (history.length > historyPoints) {
7496
+ history.shift();
7497
+ }
7498
+ }
7499
+ }
7500
+ if (telemetryHistory.has(selectedChartKey) && chart) {
7501
+ const selectedHistory = telemetryHistory.get(selectedChartKey);
7502
+ chart.data.datasets[0].data = selectedHistory;
7456
7503
  chart.update("none");
7457
7504
  }
7458
7505
  }
7506
+ function getFormattedValue(key, value) {
7507
+ const config = TELEMETRY_CONFIG[key];
7508
+ if (!config) return value.toFixed(2);
7509
+ if (key === "consumption" || key === "power") {
7510
+ if (value >= 1e3) {
7511
+ return `${(value / 1e3).toFixed(2)} kW`;
7512
+ }
7513
+ return `${value.toFixed(0)} W`;
7514
+ }
7515
+ return `${value.toFixed(config.decimals)} ${config.unit}`;
7516
+ }
7459
7517
  function initializeChart() {
7460
7518
  const Chart = window.Chart;
7461
7519
  if (!Chart) {
@@ -7463,23 +7521,26 @@ async function openRealTimeTelemetryModal(params) {
7463
7521
  return;
7464
7522
  }
7465
7523
  chartContainer.style.display = "block";
7524
+ const config = TELEMETRY_CONFIG[selectedChartKey] || { label: selectedChartKey, unit: "" };
7466
7525
  chart = new Chart(chartCanvas, {
7467
7526
  type: "line",
7468
7527
  data: {
7469
7528
  datasets: [{
7470
- label: "Pot\xEAncia",
7529
+ label: config.label,
7471
7530
  data: [],
7472
7531
  borderColor: "#667eea",
7473
7532
  backgroundColor: "rgba(102, 126, 234, 0.1)",
7474
7533
  borderWidth: 2,
7475
7534
  fill: true,
7476
7535
  tension: 0.4,
7477
- pointRadius: 0
7536
+ pointRadius: 3,
7537
+ pointHoverRadius: 5
7478
7538
  }]
7479
7539
  },
7480
7540
  options: {
7481
7541
  responsive: true,
7482
7542
  maintainAspectRatio: false,
7543
+ animation: false,
7483
7544
  plugins: {
7484
7545
  legend: { display: false },
7485
7546
  tooltip: {
@@ -7487,10 +7548,18 @@ async function openRealTimeTelemetryModal(params) {
7487
7548
  title: function(context) {
7488
7549
  const timestamp = context[0].parsed.x;
7489
7550
  const date = new Date(timestamp);
7490
- return date.toLocaleTimeString(locale);
7551
+ return date.toLocaleString(locale, {
7552
+ day: "2-digit",
7553
+ month: "2-digit",
7554
+ year: "numeric",
7555
+ hour: "2-digit",
7556
+ minute: "2-digit",
7557
+ second: "2-digit"
7558
+ });
7491
7559
  },
7492
7560
  label: function(context) {
7493
- return `${context.parsed.y.toFixed(2)} kW`;
7561
+ const value = context.parsed.y;
7562
+ return getFormattedValue(selectedChartKey, value);
7494
7563
  }
7495
7564
  }
7496
7565
  }
@@ -7499,23 +7568,57 @@ async function openRealTimeTelemetryModal(params) {
7499
7568
  x: {
7500
7569
  type: "linear",
7501
7570
  ticks: {
7571
+ maxRotation: 45,
7572
+ minRotation: 0,
7502
7573
  callback: function(value) {
7503
7574
  const date = new Date(value);
7504
- return date.toLocaleTimeString(locale, { hour: "2-digit", minute: "2-digit" });
7575
+ return date.toLocaleTimeString(locale, {
7576
+ hour: "2-digit",
7577
+ minute: "2-digit",
7578
+ second: "2-digit"
7579
+ });
7505
7580
  }
7581
+ },
7582
+ title: {
7583
+ display: true,
7584
+ text: "Hora"
7506
7585
  }
7507
7586
  },
7508
7587
  y: {
7509
7588
  beginAtZero: true,
7589
+ ticks: {
7590
+ callback: function(value) {
7591
+ if (selectedChartKey === "consumption" || selectedChartKey === "power") {
7592
+ if (value >= 1e3) {
7593
+ return `${(value / 1e3).toFixed(1)} kW`;
7594
+ }
7595
+ return `${value} W`;
7596
+ }
7597
+ return `${value} ${config.unit}`;
7598
+ }
7599
+ },
7510
7600
  title: {
7511
7601
  display: true,
7512
- text: "kW"
7602
+ text: selectedChartKey === "consumption" || selectedChartKey === "power" ? "W" : config.unit
7513
7603
  }
7514
7604
  }
7515
7605
  }
7516
7606
  }
7517
7607
  });
7518
7608
  }
7609
+ function updateChartKey(newKey) {
7610
+ selectedChartKey = newKey;
7611
+ if (chart) {
7612
+ chart.destroy();
7613
+ chart = null;
7614
+ }
7615
+ initializeChart();
7616
+ if (telemetryHistory.has(selectedChartKey)) {
7617
+ const selectedHistory = telemetryHistory.get(selectedChartKey);
7618
+ chart.data.datasets[0].data = selectedHistory;
7619
+ chart.update("none");
7620
+ }
7621
+ }
7519
7622
  async function refreshData() {
7520
7623
  try {
7521
7624
  const data = await fetchLatestTelemetry();
@@ -7527,9 +7630,7 @@ async function openRealTimeTelemetryModal(params) {
7527
7630
  if (loadingState.style.display !== "none") {
7528
7631
  loadingState.style.display = "none";
7529
7632
  telemetryContent.style.display = "block";
7530
- if (telemetryKeys.includes("power")) {
7531
- initializeChart();
7532
- }
7633
+ initializeChart();
7533
7634
  }
7534
7635
  } catch (error) {
7535
7636
  console.error("[RealTimeTelemetry] Error fetching data:", error);
@@ -7597,6 +7698,10 @@ async function openRealTimeTelemetryModal(params) {
7597
7698
  closeBtn.addEventListener("click", closeModal);
7598
7699
  pauseBtn.addEventListener("click", togglePause);
7599
7700
  exportBtn.addEventListener("click", exportToCSV2);
7701
+ chartKeySelector.addEventListener("change", (e) => {
7702
+ const newKey = e.target.value;
7703
+ updateChartKey(newKey);
7704
+ });
7600
7705
  overlay.addEventListener("click", (e) => {
7601
7706
  if (e.target === overlay) {
7602
7707
  closeModal();