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
|
|
@ -1,9 +1,9 @@
|
|||
const API_BASE = 'http://192.168.1.195:8000'
|
||||
const DEV_EUI = '0586fe41112d83d9';
|
||||
|
||||
async function fetchConsumption({ start, end, granularity }) {
|
||||
|
||||
async function fetchConsumption({device_eui, start, end, granularity }) {
|
||||
const params = new URLSearchParams({ start, end, granularity });
|
||||
const url = `${API_BASE}/readings/${DEV_EUI}?${params}`;
|
||||
const url = `${API_BASE}/readings/${device_eui}?${params}`;
|
||||
|
||||
const result = await fetch(url);
|
||||
if (!result.ok) {
|
||||
|
|
@ -13,4 +13,17 @@ async function fetchConsumption({ start, end, granularity }) {
|
|||
const raw = await result.json();
|
||||
|
||||
return raw.points;
|
||||
}
|
||||
|
||||
async function fetchDevices(){
|
||||
const url = `${API_BASE}/devices`;
|
||||
const result = await fetch(url);
|
||||
|
||||
if (!result.ok) {
|
||||
const err = await result.json().catch(() => ({}));
|
||||
throw new Error(err.detail || `Erreur HTTP ${result.status}`);
|
||||
}
|
||||
const devices = await result.json();
|
||||
|
||||
return devices;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue