From 39557c3c09132224918da4fa975747dff59c55bd Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 7 Jan 2024 02:07:54 +0100 Subject: [PATCH] Update Settings.js make it possible to deactivate unused protocol --- src/views/Settings.js | 248 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 241 insertions(+), 7 deletions(-) diff --git a/src/views/Settings.js b/src/views/Settings.js index a268842..4557d43 100644 --- a/src/views/Settings.js +++ b/src/views/Settings.js @@ -5,6 +5,15 @@ import { toast } from 'react-hot-toast'; const Settings = ({ HOST_IP, API_KEY }) => { const [enable, setEnable] = useState(false); const [port, setPort] = useState("80"); + const [yeelight, setYeelight] = useState(true); + const [native_multi, setNative_multi] = useState(true); + const [tasmota, setTasmota] = useState(true); + const [wled, setWled] = useState(true); + const [shelly, setShelly] = useState(true); + const [esphome, setEsphome] = useState(true); + const [hyperion, setHyperion] = useState(true); + const [tpkasa, setTpkasa] = useState(true); + const [elgato, setElgato] = useState(true); useEffect(() => { axios @@ -17,12 +26,95 @@ const Settings = ({ HOST_IP, API_KEY }) => { console.error(error); toast.error(`Error occurred: ${error.message}`); }); + axios + .get(`${HOST_IP}/api/${API_KEY}/config/yeelight`) + .then((result) => { + setYeelight(result.data["enabled"]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); + axios + .get(`${HOST_IP}/api/${API_KEY}/config/native_multi`) + .then((result) => { + setNative_multi(result.data["enabled"]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); + axios + .get(`${HOST_IP}/api/${API_KEY}/config/tasmota`) + .then((result) => { + setTasmota(result.data["enabled"]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); + axios + .get(`${HOST_IP}/api/${API_KEY}/config/wled`) + .then((result) => { + setWled(result.data["enabled"]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); + axios + .get(`${HOST_IP}/api/${API_KEY}/config/shelly`) + .then((result) => { + setShelly(result.data["enabled"]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); + axios + .get(`${HOST_IP}/api/${API_KEY}/config/esphome`) + .then((result) => { + setEsphome(result.data["enabled"]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); + axios + .get(`${HOST_IP}/api/${API_KEY}/config/hyperion`) + .then((result) => { + setHyperion(result.data["enabled"]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); + axios + .get(`${HOST_IP}/api/${API_KEY}/config/tpkasa`) + .then((result) => { + setTpkasa(result.data["enabled"]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); + axios + .get(`${HOST_IP}/api/${API_KEY}/config/elgato`) + .then((result) => { + setElgato(result.data["enabled"]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); }, [HOST_IP, API_KEY]); const toggleEnable = (e) => { setEnable(e); axios - .put(`${HOST_IP}/api/${API_KEY}/config`, { port: { enabled: e } }) + .put(`${HOST_IP}/api/${API_KEY}/config`, { + port: { enabled: e } + }) .then((fetchedData) => { console.log(fetchedData.data); toast.success(`Port ${e ? "activated" : "deactivated"}`); @@ -50,14 +142,38 @@ const Settings = ({ HOST_IP, API_KEY }) => { }); }; + const onSubmit_protocol = (e) => { + e.preventDefault(); + axios + .put(`${HOST_IP}/api/${API_KEY}/config`, { + yeelight: { enabled: yeelight }, + native_multi: { enabled: native_multi }, + tasmota: { enabled: tasmota }, + wled: { enabled: wled }, + shelly: { enabled: shelly }, + esphome: { enabled: esphome }, + hyperion: { enabled: hyperion }, + tpkasa: { enabled: tpkasa }, + elgato: { enabled: elgato }, + }) + .then((fetchedData) => { + console.log(fetchedData.data); + toast.success("Successfully saved"); + }) + .catch((error) => { + console.error(error); + toast.error(`Error occurred: ${error.message}`); + }); + }; + return (
-
-
Add extra port for searching
-

This wil make the bridge search on other ports.

-

If disabled the bridge wil only search on port 80.

-

The standard port is 80, always include port 80.

-

To add ports separate the ports with "," ex: 80,81,82

+
+
Add extra port for searching
+

This wil make the bridge search on other ports.

+

If disabled the bridge wil only search on port 80.

+

The standard port is 80, always include port 80.

+

To add ports separate the ports with "," ex: 80,81,82

onSubmit(e)}>
+ +
+
Search Config
+

Set which protocol to find.

+
onSubmit_protocol(e)}> +
+

Yeelight

+ +
+
+

Native_multi

+ +
+
+

Tasmota

+ +
+
+

Wled

+ +
+
+

Shelly

+ +
+
+

Esphome

+ +
+
+

Hyperion

+ +
+
+

Tpkasa

+ +
+
+

Elgato

+ +
+
+ +
+
+
); };