Add PSU
This commit is contained in:
@@ -41,6 +41,19 @@ export interface JobState {
|
||||
state: string;
|
||||
}
|
||||
|
||||
export interface ConnectionState {
|
||||
current: {
|
||||
baudrate: number | null;
|
||||
port: string | null;
|
||||
printerProfile: string;
|
||||
state: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PsuControlState {
|
||||
isPSUOn: boolean;
|
||||
}
|
||||
|
||||
export class OctoPrintClient {
|
||||
private baseUrl: string;
|
||||
private apiKey: string;
|
||||
@@ -74,6 +87,14 @@ export class OctoPrintClient {
|
||||
return res.json() as Promise<JobState>;
|
||||
}
|
||||
|
||||
async getConnectionState(): Promise<ConnectionState> {
|
||||
const res = await fetch(`${this.baseUrl}/connection`, {
|
||||
headers: this.headers,
|
||||
});
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
||||
return res.json() as Promise<ConnectionState>;
|
||||
}
|
||||
|
||||
async pausePrint(): Promise<void> {
|
||||
await fetch(`${this.baseUrl}/job`, {
|
||||
method: "POST",
|
||||
@@ -114,6 +135,30 @@ export class OctoPrintClient {
|
||||
}
|
||||
}
|
||||
|
||||
async getPSUState(): Promise<PsuControlState> {
|
||||
const res = await fetch(`${this.baseUrl}/plugin/psucontrol`, {
|
||||
headers: this.headers,
|
||||
});
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
||||
return res.json() as Promise<PsuControlState>;
|
||||
}
|
||||
|
||||
async turnPSUOn(): Promise<void> {
|
||||
await fetch(`${this.baseUrl}/plugin/psucontrol`, {
|
||||
method: "POST",
|
||||
headers: this.headers,
|
||||
body: JSON.stringify({ command: "turnPSUOn" }),
|
||||
});
|
||||
}
|
||||
|
||||
async turnPSUOff(): Promise<void> {
|
||||
await fetch(`${this.baseUrl}/plugin/psucontrol`, {
|
||||
method: "POST",
|
||||
headers: this.headers,
|
||||
body: JSON.stringify({ command: "turnPSUOff" }),
|
||||
});
|
||||
}
|
||||
|
||||
async testConnection(): Promise<boolean> {
|
||||
try {
|
||||
const res = await fetch(`${this.baseUrl}/version`, { headers: this.headers });
|
||||
|
||||
Reference in New Issue
Block a user