From bdb39de0380d1862389701fea6684ab1e7c3f601 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Tue, 9 Jun 2026 15:56:41 +0530 Subject: [PATCH] Init file --- .gitignore | 9 +++++++++ src/data.js | 11 +++++++++++ src/ui.js | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 .gitignore create mode 100644 src/data.js create mode 100644 src/ui.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..acad114 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +node_modules/ +/.pnp +.pnp.js +.DS_Store +npm-debug.log* +yarn-debug.log* +yarn-error.log* +package-lock.json +.env diff --git a/src/data.js b/src/data.js new file mode 100644 index 0000000..f8ae084 --- /dev/null +++ b/src/data.js @@ -0,0 +1,11 @@ +async function fetchTemperature(zoneId) { + const res = await fetch(`/api/v1/zones/${zoneId}/primary/temperature`); + return res.json(); +} + +// Don't change this function signature +export async function attachChart(chartInstance, zoneId) { + await fetchTemperature(zoneId).then(temp => { + chartInstance.update(temp); + }); +} diff --git a/src/ui.js b/src/ui.js new file mode 100644 index 0000000..0c0af46 --- /dev/null +++ b/src/ui.js @@ -0,0 +1,9 @@ +// This file can not be modified. +// Each zone has one corresponding chart. +// UI code calls attachChart for each zone and corresponding chart. +import { attachChart } from './data.js'; +const zones = ['zone-a', 'zone-b', 'zone-c', /* ... */]; +for (const zoneId of zones) { + const chart = createChartForZone(zoneId); + attachChart(chart, zoneId); +}