Display relays status

This commit is contained in:
2024-09-25 19:35:39 +02:00
parent 78ace02d15
commit 3c2fa18d9a
6 changed files with 101 additions and 8 deletions

View File

@ -1,6 +1,14 @@
import { APIClient } from "./ApiClient";
import { Device, DeviceRelay } from "./DeviceApi";
export interface RelayStatus {
id: string;
on: boolean;
for: number;
}
export type RelaysStatus = Map<string, RelayStatus>;
export class RelayApi {
/**
* Get the full list of relays
@ -49,4 +57,22 @@ export class RelayApi {
uri: `/relay/${relay.id}`,
});
}
/**
* Get the status of all relays
*/
static async GetRelaysStatus(): Promise<RelaysStatus> {
const data: any[] = (
await APIClient.exec({
method: "GET",
uri: `/relays/status`,
})
).data;
const map = new Map();
for (let r of data) {
map.set(r.id, r);
}
return map;
}
}