feat: use device choice in API consumption request instead of hardcoded
This commit is contained in:
parent
f4b7daabd3
commit
319821ce59
3 changed files with 37 additions and 4 deletions
|
|
@ -10,15 +10,18 @@ async function init() {
|
|||
document.getElementById("date-end").valueAsDate = end;
|
||||
document.getElementById("btn-refresh").addEventListener("click", loadData);
|
||||
|
||||
loadData();
|
||||
await loadDevices();
|
||||
await loadData();
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
const start = document.getElementById("date-start").value;
|
||||
const end = document.getElementById("date-end").value;
|
||||
const granularity = document.getElementById("granularity").value;
|
||||
const device_eui = document.getElementById("device").value;
|
||||
|
||||
const points = await fetchConsumption({
|
||||
device_eui: device_eui,
|
||||
start: start,
|
||||
end: end,
|
||||
granularity: granularity,
|
||||
|
|
@ -50,3 +53,15 @@ function updateKPIs(points) {
|
|||
avgDisplay.textContent = avgValue.toFixed(3);
|
||||
countDisplay.textContent = points.length;
|
||||
}
|
||||
|
||||
async function loadDevices() {
|
||||
const selectDeviceElmt = document.getElementById("device");
|
||||
|
||||
const devices = await fetchDevices();
|
||||
|
||||
devices.forEach((device) => {
|
||||
selectDeviceElmt.add(new Option(device.device_eui))
|
||||
});
|
||||
|
||||
selectDeviceElmt.value = devices[0]?.device_eui ?? "";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue