Check power usage

This commit is contained in:
hodasemi 2023-09-25 13:04:02 +02:00
parent 66797917cc
commit ad23b6ecee

View file

@ -109,7 +109,7 @@ async function startup() {
device_power_state_entry.appendChild(device_power_state);
if (devices[i][2] == true) {
if (devices[i][2] == true && device_state["power_draw"] < 15) {
let device_power_on = document.createElement('button');
device_power_on.innerText = "On"
device_power_on.onclick = async () => { await power_on(device_id) };
@ -179,8 +179,20 @@ async function power_on(plug) {
}
async function power_off(plug) {
// get plug status
const device_status_response = await fetch(
"/plug_state/" + device_id,
{
method: "GET"
}
);
let device_state = JSON.parse(await device_status_response.json());
if (device_state["power_draw"] < 15) {
await change_plug_state(plug, "power", "off")
}
}
async function change_device_name(plug, name) {
const response = await fetch(