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-22 22:19:48 +02:00
|
|
|
export interface UpdatedInfo {
|
|
|
|
name: string;
|
|
|
|
description: string;
|
|
|
|
enabled: boolean;
|
|
|
|
}
|
|
|
|
|
2024-07-18 20:06:46 +02:00
|
|
|
export function DeviceURL(d: Device): string {
|
|
|
|
return `/dev/${encodeURIComponent(d.id)}`;
|
2024-07-17 23:19:04 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-07-18 20:06:46 +02:00
|
|
|
/**
|
|
|
|
* Get the information about a single device
|
|
|
|
*/
|
|
|
|
static async GetSingle(id: string): Promise<Device> {
|
|
|
|
return (
|
|
|
|
await APIClient.exec({
|
|
|
|
uri: `/device/${encodeURIComponent(id)}`,
|
|
|
|
method: "GET",
|
|
|
|
})
|
|
|
|
).data;
|
|
|
|
}
|
|
|
|
|
2024-07-22 22:19:48 +02:00
|
|
|
/**
|
|
|
|
* Update a device general information
|
|
|
|
*/
|
|
|
|
static async Update(d: Device, info: UpdatedInfo): Promise<void> {
|
|
|
|
await APIClient.exec({
|
|
|
|
uri: `/device/${encodeURIComponent(d.id)}`,
|
|
|
|
method: "PATCH",
|
|
|
|
jsonData: info,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|