2024-07-03 19:17:47 +02:00
|
|
|
import { APIClient } from "./ApiClient";
|
|
|
|
|
|
|
|
export interface DeviceInfo {
|
|
|
|
reference: string;
|
|
|
|
version: string;
|
|
|
|
max_relays: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DailyMinRuntime {
|
|
|
|
min_runtime: number;
|
|
|
|
reset_time: number;
|
|
|
|
catch_up_hours: number[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DeviceRelay {
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
enabled: boolean;
|
|
|
|
priority: number;
|
|
|
|
consumption: number;
|
|
|
|
minimal_uptime: number;
|
|
|
|
minimal_downtime: number;
|
|
|
|
daily_runtime?: DailyMinRuntime;
|
|
|
|
depends_on: DeviceRelay[];
|
|
|
|
conflicts_with: DeviceRelay[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Device {
|
|
|
|
id: string;
|
|
|
|
info: DeviceInfo;
|
|
|
|
time_create: number;
|
|
|
|
time_update: number;
|
|
|
|
name: string;
|
|
|
|
description: string;
|
|
|
|
validated: boolean;
|
|
|
|
enabled: boolean;
|
|
|
|
relays: DeviceRelay[];
|
|
|
|
}
|
|
|
|
|
2024-07-17 23:19:04 +02:00
|
|
|
export function DeviceURL(d: Device, edit: boolean = false): string {
|
|
|
|
return `/dev/${d.id}${edit ? "/edit" : ""}`;
|
|
|
|
}
|
|
|
|
|
2024-07-03 19:17:47 +02:00
|
|
|
export class DeviceApi {
|
|
|
|
/**
|
|
|
|
* Get the list of pending devices
|
|
|
|
*/
|
|
|
|
static async PendingList(): Promise<Device[]> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
uri: "/devices/list_pending",
|
|
|
|
method: "GET",
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
2024-07-04 19:52:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of validated devices
|
|
|
|
*/
|
|
|
|
static async ValidatedList(): Promise<Device[]> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
uri: "/devices/list_validated",
|
|
|
|
method: "GET",
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
|
|
|
|
2024-07-03 21:32:32 +02:00
|
|
|
/**
|
|
|
|
* Validate a device
|
|
|
|
*/
|
|
|
|
static async Validate(d: Device): Promise<void> {
|
|
|
|
await APIClient.exec({
|
|
|
|
uri: `/device/${encodeURIComponent(d.id)}/validate`,
|
|
|
|
method: "POST",
|
|
|
|
});
|
|
|
|
}
|
2024-07-03 21:10:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a device
|
|
|
|
*/
|
|
|
|
static async Delete(d: Device): Promise<void> {
|
|
|
|
await APIClient.exec({
|
|
|
|
uri: `/device/${encodeURIComponent(d.id)}`,
|
|
|
|
method: "DELETE",
|
|
|
|
});
|
|
|
|
}
|
2024-07-03 19:17:47 +02:00
|
|
|
}
|