const API_BASE = 'https://api.agreg.ungol.fr' async function fetchConsumption({device_eui, start, end, granularity }) { const params = new URLSearchParams({ start, end, granularity }); const url = `${API_BASE}/readings/${device_eui}?${params}`; 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; } 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; }