This commit is contained in:
Carsten Graf
2026-03-05 15:59:23 +01:00
parent d5353b3c2b
commit b338281a97
7 changed files with 197 additions and 0 deletions

View File

@@ -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 });