Display relay status on relays page

This commit is contained in:
2024-09-09 21:27:15 +02:00
parent 7cac6aeb35
commit a97614ce44
3 changed files with 52 additions and 5 deletions

View File

@ -45,6 +45,14 @@ export interface UpdatedInfo {
enabled: boolean;
}
export interface DeviceState {
id: string;
last_ping: number;
online: boolean;
}
export type DevicesState = Map<string, DeviceState>;
export function DeviceURL(d: Device): string {
return `/dev/${encodeURIComponent(d.id)}`;
}
@ -74,6 +82,22 @@ export class DeviceApi {
).data;
}
/**
* Get the state of devices
*/
static async DevicesState(): Promise<DevicesState> {
const devs: DeviceState[] = (
await APIClient.exec({
uri: "/devices/state",
method: "GET",
})
).data;
const m = new Map();
devs.forEach((d) => m.set(d.id, d));
return m;
}
/**
* Validate a device
*/