myio-js-library 0.1.135 → 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 +134 -21
- package/dist/index.js +134 -21
- package/dist/myio-js-library.umd.js +134 -21
- package/dist/myio-js-library.umd.min.js +1 -1
- package/package.json +1 -1
|
@@ -6975,15 +6975,23 @@ ${rangeText}`;
|
|
|
6975
6975
|
|
|
6976
6976
|
// src/components/RealTimeTelemetryModal.ts
|
|
6977
6977
|
var TELEMETRY_CONFIG = {
|
|
6978
|
-
|
|
6978
|
+
// Voltage phases
|
|
6979
|
+
voltage_a: { label: "Tens\xE3o Fase A", unit: "V", icon: "\u26A1", decimals: 1 },
|
|
6980
|
+
voltage_b: { label: "Tens\xE3o Fase B", unit: "V", icon: "\u26A1", decimals: 1 },
|
|
6981
|
+
voltage_c: { label: "Tens\xE3o Fase C", unit: "V", icon: "\u26A1", decimals: 1 },
|
|
6982
|
+
// Current
|
|
6983
|
+
total_current: { label: "Corrente Total", unit: "A", icon: "\u{1F50C}", decimals: 2 },
|
|
6979
6984
|
current: { label: "Corrente", unit: "A", icon: "\u{1F50C}", decimals: 2 },
|
|
6980
|
-
|
|
6985
|
+
// Power and Energy
|
|
6986
|
+
consumption: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
|
|
6987
|
+
power: { label: "Pot\xEAncia", unit: "W", icon: "\u2699\uFE0F", decimals: 0 },
|
|
6981
6988
|
energy: { label: "Energia", unit: "kWh", icon: "\u{1F4CA}", decimals: 1 },
|
|
6982
|
-
temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 },
|
|
6983
6989
|
activePower: { label: "Pot\xEAncia Ativa", unit: "kW", icon: "\u2699\uFE0F", decimals: 2 },
|
|
6984
6990
|
reactivePower: { label: "Pot\xEAncia Reativa", unit: "kVAr", icon: "\u{1F504}", decimals: 2 },
|
|
6985
6991
|
apparentPower: { label: "Pot\xEAncia Aparente", unit: "kVA", icon: "\u{1F4C8}", decimals: 2 },
|
|
6986
|
-
powerFactor: { label: "Fator de Pot\xEAncia", unit: "", icon: "\u{1F4D0}", decimals: 3 }
|
|
6992
|
+
powerFactor: { label: "Fator de Pot\xEAncia", unit: "", icon: "\u{1F4D0}", decimals: 3 },
|
|
6993
|
+
// Temperature
|
|
6994
|
+
temperature: { label: "Temperatura", unit: "\xB0C", icon: "\u{1F321}\uFE0F", decimals: 1 }
|
|
6987
6995
|
};
|
|
6988
6996
|
var STRINGS = {
|
|
6989
6997
|
"pt-BR": {
|
|
@@ -7022,7 +7030,7 @@ ${rangeText}`;
|
|
|
7022
7030
|
token,
|
|
7023
7031
|
deviceId,
|
|
7024
7032
|
deviceLabel = "Dispositivo",
|
|
7025
|
-
telemetryKeys = ["
|
|
7033
|
+
telemetryKeys = ["voltage_a", "voltage_b", "voltage_c", "total_current", "consumption"],
|
|
7026
7034
|
refreshInterval = 8e3,
|
|
7027
7035
|
historyPoints = 50,
|
|
7028
7036
|
onClose,
|
|
@@ -7032,7 +7040,9 @@ ${rangeText}`;
|
|
|
7032
7040
|
let refreshIntervalId = null;
|
|
7033
7041
|
let isPaused = false;
|
|
7034
7042
|
let telemetryHistory = /* @__PURE__ */ new Map();
|
|
7043
|
+
let lastKnownValues = /* @__PURE__ */ new Map();
|
|
7035
7044
|
let chart = null;
|
|
7045
|
+
let selectedChartKey = "consumption";
|
|
7036
7046
|
const overlay = document.createElement("div");
|
|
7037
7047
|
overlay.className = "myio-realtime-telemetry-overlay";
|
|
7038
7048
|
overlay.innerHTML = `
|
|
@@ -7193,7 +7203,27 @@ ${rangeText}`;
|
|
|
7193
7203
|
}
|
|
7194
7204
|
|
|
7195
7205
|
.myio-telemetry-chart {
|
|
7196
|
-
height:
|
|
7206
|
+
height: 250px;
|
|
7207
|
+
}
|
|
7208
|
+
|
|
7209
|
+
.myio-telemetry-selector {
|
|
7210
|
+
padding: 8px 12px;
|
|
7211
|
+
border: 1px solid #ddd;
|
|
7212
|
+
border-radius: 6px;
|
|
7213
|
+
font-size: 14px;
|
|
7214
|
+
background: white;
|
|
7215
|
+
cursor: pointer;
|
|
7216
|
+
transition: border-color 0.2s;
|
|
7217
|
+
}
|
|
7218
|
+
|
|
7219
|
+
.myio-telemetry-selector:hover {
|
|
7220
|
+
border-color: #667eea;
|
|
7221
|
+
}
|
|
7222
|
+
|
|
7223
|
+
.myio-telemetry-selector:focus {
|
|
7224
|
+
outline: none;
|
|
7225
|
+
border-color: #667eea;
|
|
7226
|
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
7197
7227
|
}
|
|
7198
7228
|
|
|
7199
7229
|
.myio-realtime-telemetry-footer {
|
|
@@ -7303,7 +7333,16 @@ ${rangeText}`;
|
|
|
7303
7333
|
<div class="myio-telemetry-cards-grid" id="telemetry-cards"></div>
|
|
7304
7334
|
|
|
7305
7335
|
<div class="myio-telemetry-chart-container" id="chart-container" style="display: none;">
|
|
7306
|
-
<
|
|
7336
|
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
|
|
7337
|
+
<h3 class="myio-telemetry-chart-title" id="chart-title" style="margin: 0;">Hist\xF3rico de Telemetria</h3>
|
|
7338
|
+
<select id="chart-key-selector" class="myio-telemetry-selector">
|
|
7339
|
+
<option value="consumption">Pot\xEAncia</option>
|
|
7340
|
+
<option value="total_current">Corrente Total</option>
|
|
7341
|
+
<option value="voltage_a">Tens\xE3o Fase A</option>
|
|
7342
|
+
<option value="voltage_b">Tens\xE3o Fase B</option>
|
|
7343
|
+
<option value="voltage_c">Tens\xE3o Fase C</option>
|
|
7344
|
+
</select>
|
|
7345
|
+
</div>
|
|
7307
7346
|
<canvas class="myio-telemetry-chart" id="telemetry-chart"></canvas>
|
|
7308
7347
|
</div>
|
|
7309
7348
|
</div>
|
|
@@ -7345,6 +7384,7 @@ ${rangeText}`;
|
|
|
7345
7384
|
const telemetryCards = document.getElementById("telemetry-cards");
|
|
7346
7385
|
const chartContainer = document.getElementById("chart-container");
|
|
7347
7386
|
const chartCanvas = document.getElementById("telemetry-chart");
|
|
7387
|
+
const chartKeySelector = document.getElementById("chart-key-selector");
|
|
7348
7388
|
const statusIndicator = document.getElementById("status-indicator");
|
|
7349
7389
|
const statusText = document.getElementById("status-text");
|
|
7350
7390
|
const lastUpdateText = document.getElementById("last-update-text");
|
|
@@ -7436,16 +7476,42 @@ ${rangeText}`;
|
|
|
7436
7476
|
}
|
|
7437
7477
|
const history = telemetryHistory.get(tel.key);
|
|
7438
7478
|
history.push({ x: now, y: tel.value });
|
|
7479
|
+
lastKnownValues.set(tel.key, tel.value);
|
|
7439
7480
|
if (history.length > historyPoints) {
|
|
7440
7481
|
history.shift();
|
|
7441
7482
|
}
|
|
7442
7483
|
}
|
|
7443
|
-
|
|
7444
|
-
const
|
|
7445
|
-
|
|
7484
|
+
for (const key of telemetryKeys) {
|
|
7485
|
+
const receivedKeys = values.map((v) => v.key);
|
|
7486
|
+
if (!receivedKeys.includes(key) && lastKnownValues.has(key)) {
|
|
7487
|
+
if (!telemetryHistory.has(key)) {
|
|
7488
|
+
telemetryHistory.set(key, []);
|
|
7489
|
+
}
|
|
7490
|
+
const history = telemetryHistory.get(key);
|
|
7491
|
+
const lastValue = lastKnownValues.get(key);
|
|
7492
|
+
history.push({ x: now, y: lastValue });
|
|
7493
|
+
if (history.length > historyPoints) {
|
|
7494
|
+
history.shift();
|
|
7495
|
+
}
|
|
7496
|
+
}
|
|
7497
|
+
}
|
|
7498
|
+
if (telemetryHistory.has(selectedChartKey) && chart) {
|
|
7499
|
+
const selectedHistory = telemetryHistory.get(selectedChartKey);
|
|
7500
|
+
chart.data.datasets[0].data = selectedHistory;
|
|
7446
7501
|
chart.update("none");
|
|
7447
7502
|
}
|
|
7448
7503
|
}
|
|
7504
|
+
function getFormattedValue(key, value) {
|
|
7505
|
+
const config = TELEMETRY_CONFIG[key];
|
|
7506
|
+
if (!config) return value.toFixed(2);
|
|
7507
|
+
if (key === "consumption" || key === "power") {
|
|
7508
|
+
if (value >= 1e3) {
|
|
7509
|
+
return `${(value / 1e3).toFixed(2)} kW`;
|
|
7510
|
+
}
|
|
7511
|
+
return `${value.toFixed(0)} W`;
|
|
7512
|
+
}
|
|
7513
|
+
return `${value.toFixed(config.decimals)} ${config.unit}`;
|
|
7514
|
+
}
|
|
7449
7515
|
function initializeChart() {
|
|
7450
7516
|
const Chart = window.Chart;
|
|
7451
7517
|
if (!Chart) {
|
|
@@ -7453,23 +7519,26 @@ ${rangeText}`;
|
|
|
7453
7519
|
return;
|
|
7454
7520
|
}
|
|
7455
7521
|
chartContainer.style.display = "block";
|
|
7522
|
+
const config = TELEMETRY_CONFIG[selectedChartKey] || { label: selectedChartKey, unit: "" };
|
|
7456
7523
|
chart = new Chart(chartCanvas, {
|
|
7457
7524
|
type: "line",
|
|
7458
7525
|
data: {
|
|
7459
7526
|
datasets: [{
|
|
7460
|
-
label:
|
|
7527
|
+
label: config.label,
|
|
7461
7528
|
data: [],
|
|
7462
7529
|
borderColor: "#667eea",
|
|
7463
7530
|
backgroundColor: "rgba(102, 126, 234, 0.1)",
|
|
7464
7531
|
borderWidth: 2,
|
|
7465
7532
|
fill: true,
|
|
7466
7533
|
tension: 0.4,
|
|
7467
|
-
pointRadius:
|
|
7534
|
+
pointRadius: 3,
|
|
7535
|
+
pointHoverRadius: 5
|
|
7468
7536
|
}]
|
|
7469
7537
|
},
|
|
7470
7538
|
options: {
|
|
7471
7539
|
responsive: true,
|
|
7472
7540
|
maintainAspectRatio: false,
|
|
7541
|
+
animation: false,
|
|
7473
7542
|
plugins: {
|
|
7474
7543
|
legend: { display: false },
|
|
7475
7544
|
tooltip: {
|
|
@@ -7477,10 +7546,18 @@ ${rangeText}`;
|
|
|
7477
7546
|
title: function(context) {
|
|
7478
7547
|
const timestamp = context[0].parsed.x;
|
|
7479
7548
|
const date = new Date(timestamp);
|
|
7480
|
-
return date.
|
|
7549
|
+
return date.toLocaleString(locale, {
|
|
7550
|
+
day: "2-digit",
|
|
7551
|
+
month: "2-digit",
|
|
7552
|
+
year: "numeric",
|
|
7553
|
+
hour: "2-digit",
|
|
7554
|
+
minute: "2-digit",
|
|
7555
|
+
second: "2-digit"
|
|
7556
|
+
});
|
|
7481
7557
|
},
|
|
7482
7558
|
label: function(context) {
|
|
7483
|
-
|
|
7559
|
+
const value = context.parsed.y;
|
|
7560
|
+
return getFormattedValue(selectedChartKey, value);
|
|
7484
7561
|
}
|
|
7485
7562
|
}
|
|
7486
7563
|
}
|
|
@@ -7489,23 +7566,57 @@ ${rangeText}`;
|
|
|
7489
7566
|
x: {
|
|
7490
7567
|
type: "linear",
|
|
7491
7568
|
ticks: {
|
|
7569
|
+
maxRotation: 45,
|
|
7570
|
+
minRotation: 0,
|
|
7492
7571
|
callback: function(value) {
|
|
7493
7572
|
const date = new Date(value);
|
|
7494
|
-
return date.toLocaleTimeString(locale, {
|
|
7573
|
+
return date.toLocaleTimeString(locale, {
|
|
7574
|
+
hour: "2-digit",
|
|
7575
|
+
minute: "2-digit",
|
|
7576
|
+
second: "2-digit"
|
|
7577
|
+
});
|
|
7495
7578
|
}
|
|
7579
|
+
},
|
|
7580
|
+
title: {
|
|
7581
|
+
display: true,
|
|
7582
|
+
text: "Hora"
|
|
7496
7583
|
}
|
|
7497
7584
|
},
|
|
7498
7585
|
y: {
|
|
7499
7586
|
beginAtZero: true,
|
|
7587
|
+
ticks: {
|
|
7588
|
+
callback: function(value) {
|
|
7589
|
+
if (selectedChartKey === "consumption" || selectedChartKey === "power") {
|
|
7590
|
+
if (value >= 1e3) {
|
|
7591
|
+
return `${(value / 1e3).toFixed(1)} kW`;
|
|
7592
|
+
}
|
|
7593
|
+
return `${value} W`;
|
|
7594
|
+
}
|
|
7595
|
+
return `${value} ${config.unit}`;
|
|
7596
|
+
}
|
|
7597
|
+
},
|
|
7500
7598
|
title: {
|
|
7501
7599
|
display: true,
|
|
7502
|
-
text: "
|
|
7600
|
+
text: selectedChartKey === "consumption" || selectedChartKey === "power" ? "W" : config.unit
|
|
7503
7601
|
}
|
|
7504
7602
|
}
|
|
7505
7603
|
}
|
|
7506
7604
|
}
|
|
7507
7605
|
});
|
|
7508
7606
|
}
|
|
7607
|
+
function updateChartKey(newKey) {
|
|
7608
|
+
selectedChartKey = newKey;
|
|
7609
|
+
if (chart) {
|
|
7610
|
+
chart.destroy();
|
|
7611
|
+
chart = null;
|
|
7612
|
+
}
|
|
7613
|
+
initializeChart();
|
|
7614
|
+
if (telemetryHistory.has(selectedChartKey)) {
|
|
7615
|
+
const selectedHistory = telemetryHistory.get(selectedChartKey);
|
|
7616
|
+
chart.data.datasets[0].data = selectedHistory;
|
|
7617
|
+
chart.update("none");
|
|
7618
|
+
}
|
|
7619
|
+
}
|
|
7509
7620
|
async function refreshData() {
|
|
7510
7621
|
try {
|
|
7511
7622
|
const data = await fetchLatestTelemetry();
|
|
@@ -7517,9 +7628,7 @@ ${rangeText}`;
|
|
|
7517
7628
|
if (loadingState.style.display !== "none") {
|
|
7518
7629
|
loadingState.style.display = "none";
|
|
7519
7630
|
telemetryContent.style.display = "block";
|
|
7520
|
-
|
|
7521
|
-
initializeChart();
|
|
7522
|
-
}
|
|
7631
|
+
initializeChart();
|
|
7523
7632
|
}
|
|
7524
7633
|
} catch (error) {
|
|
7525
7634
|
console.error("[RealTimeTelemetry] Error fetching data:", error);
|
|
@@ -7587,6 +7696,10 @@ ${rangeText}`;
|
|
|
7587
7696
|
closeBtn.addEventListener("click", closeModal);
|
|
7588
7697
|
pauseBtn.addEventListener("click", togglePause);
|
|
7589
7698
|
exportBtn.addEventListener("click", exportToCSV2);
|
|
7699
|
+
chartKeySelector.addEventListener("change", (e) => {
|
|
7700
|
+
const newKey = e.target.value;
|
|
7701
|
+
updateChartKey(newKey);
|
|
7702
|
+
});
|
|
7590
7703
|
overlay.addEventListener("click", (e) => {
|
|
7591
7704
|
if (e.target === overlay) {
|
|
7592
7705
|
closeModal();
|
|
@@ -11428,7 +11541,7 @@ ${rangeText}`;
|
|
|
11428
11541
|
let startDate;
|
|
11429
11542
|
let endDate;
|
|
11430
11543
|
if (this.dateRangePicker) {
|
|
11431
|
-
const dates = this.dateRangePicker.
|
|
11544
|
+
const dates = this.dateRangePicker.getDates();
|
|
11432
11545
|
startDate = dates.startISO;
|
|
11433
11546
|
endDate = dates.endISO;
|
|
11434
11547
|
} else {
|
|
@@ -11466,7 +11579,7 @@ ${rangeText}`;
|
|
|
11466
11579
|
token: jwtToken,
|
|
11467
11580
|
deviceId: this.config.params.deviceId,
|
|
11468
11581
|
deviceLabel: this.config.params.deviceLabel || "Dispositivo",
|
|
11469
|
-
telemetryKeys: ["
|
|
11582
|
+
telemetryKeys: ["voltage_a", "voltage_b", "voltage_c", "total_current", "consumption"],
|
|
11470
11583
|
refreshInterval: 8e3,
|
|
11471
11584
|
// 8 seconds
|
|
11472
11585
|
historyPoints: 50,
|