From db045158061fa6ccb8cd8ce5f53e32b74f95ff25 Mon Sep 17 00:00:00 2001 From: Kalyax Date: Mon, 14 Nov 2022 17:50:32 +0100 Subject: [PATCH] ?????? --- index.html | 9 +++------ src/main.js | 38 +++++++++++++++----------------------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/index.html b/index.html index 0e2a985..6b99f41 100644 --- a/index.html +++ b/index.html @@ -17,20 +17,17 @@

Radiateur

- - +

Volets roulants

- - +

Eclairage

- - +
diff --git a/src/main.js b/src/main.js index bc839c6..d6d49ce 100644 --- a/src/main.js +++ b/src/main.js @@ -1,31 +1,23 @@ import './style.css'; import axios from 'axios'; -function buttonSwitch(state, button){ - button.innerText = state = 1 ? "Eteindre" : "Allumer"; -} - -async function getTemp(){ - return await axios.get("/api/temp.php"); -} +const pins = [7, 0, 2, 3, 12, 13, 14, 6]; -async function getLightState(light){ - return await axios.get("/api/light_state.php?l="+light) -} +//Fonction changeant l'état d'une lumière donnée (0-7) +//Ajoutée à window pour être utilisé dans un event de la page +window.setLightState = async (light) => { + const res = await axios.get("/api/set_light.php?light="+pins[light]); + document.getElementById("btn-"+light).innerText = res.data == 1 ? "Eteindre" : "Allumer"; +}; -async function setLightState(light){ - const pins = [7, 0, 2, 3, 12, 13, 14, 6]; - const req = await axios.post("/api/set_light.php", {light: pins[light]}) - console.log(req.data) +//Change le texte des bouttons selon l'état actuel des lumières au chargement de la page +for(let light in [0, 1, 2]){ + axios.get("/api/get_light.php?l="+pins[light]).then((res) => { + document.getElementById("btn-"+light).innerText = res.data == 1 ? "Eteindre" : "Allumer"; + }); } -window.setLightState = setLightState - -/*getLightState(0).then((data) => { - const button = document.getElementById("button-radiateur") - buttonSwitch(data.data, button) -})*/ - -getTemp().then((data) => { +//Récupère et affiche la temperature au chargement de la page +axios.get("/api/get_temp.php").then((data) => { document.getElementById("temp").innerHTML = data.data; -}) \ No newline at end of file +}); \ No newline at end of file