2026-05-30 18:02:32 +02:00
|
|
|
const API_BASE = 'https://api.agreg.ungol.fr'
|
2026-05-11 23:17:43 +02:00
|
|
|
|
2026-05-12 22:30:21 +02:00
|
|
|
|
|
|
|
|
async function fetchConsumption({device_eui, start, end, granularity }) {
|
2026-05-11 23:17:43 +02:00
|
|
|
const params = new URLSearchParams({ start, end, granularity });
|
2026-05-12 22:30:21 +02:00
|
|
|
const url = `${API_BASE}/readings/${device_eui}?${params}`;
|
2026-05-11 23:17:43 +02:00
|
|
|
|
|
|
|
|
const result = await fetch(url);
|
|
|
|
|
if (!result.ok) {
|
|
|
|
|
const err = await result.json().catch(() => ({}));
|
|
|
|
|
throw new Error(err.detail || `Erreur HTTP ${result.status}`);
|
|
|
|
|
}
|
|
|
|
|
const raw = await result.json();
|
|
|
|
|
|
|
|
|
|
return raw.points;
|
2026-05-12 22:30:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2026-05-11 23:17:43 +02:00
|
|
|
}
|