Check power usage
This commit is contained in:
parent
66797917cc
commit
ad23b6ecee
1 changed files with 14 additions and 2 deletions
|
@ -109,7 +109,7 @@ async function startup() {
|
||||||
|
|
||||||
device_power_state_entry.appendChild(device_power_state);
|
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');
|
let device_power_on = document.createElement('button');
|
||||||
device_power_on.innerText = "On"
|
device_power_on.innerText = "On"
|
||||||
device_power_on.onclick = async () => { await power_on(device_id) };
|
device_power_on.onclick = async () => { await power_on(device_id) };
|
||||||
|
@ -179,7 +179,19 @@ async function power_on(plug) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function power_off(plug) {
|
async function power_off(plug) {
|
||||||
await change_plug_state(plug, "power", "off")
|
// 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) {
|
async function change_device_name(plug, name) {
|
||||||
|
|
Loading…
Reference in a new issue