-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restart on config save/regen and fix flash all
- Loading branch information
1 parent
c25a5ba
commit 0122cba
Showing
6 changed files
with
111 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { MoonrakerPrinterState, parseMoonrakerHTTPResponse } from '../../zods/moonraker'; | ||
|
||
export const restartKlipper = async (force = false) => { | ||
const printerState = parseMoonrakerHTTPResponse( | ||
await fetch('http://localhost:7125/printer/objects/query?query=printer'), | ||
MoonrakerPrinterState, | ||
).result.status.print_state.state; | ||
if (force || ['error', 'complete', 'canceled', 'standby'].includes(printerState)) { | ||
await fetch('http://localhost:7125/printer/firmware_restart', { method: 'POST' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { z } from 'zod'; | ||
|
||
export const MoonrakerBaseResult = z.object({ | ||
eventtime: z.number(), | ||
}); | ||
export const MoonrakerPrinterState = MoonrakerBaseResult.extend({ | ||
status: z.object({ | ||
print_state: z.object({ | ||
state: z.union([ | ||
z.literal('paused'), | ||
z.literal('printing'), | ||
z.literal('complete'), | ||
z.literal('error'), | ||
z.literal('canceled'), | ||
z.literal('standby'), | ||
]), | ||
}), | ||
}), | ||
}); | ||
|
||
export const MoonrakerHTTPResponse = z.object({ | ||
result: MoonrakerBaseResult.passthrough(), | ||
}); | ||
|
||
export const parseMoonrakerHTTPResponse = <T extends z.ZodType<z.output<typeof MoonrakerBaseResult>>>( | ||
result: unknown, | ||
responseZod: T, | ||
): z.output<typeof MoonrakerHTTPResponse> & { result: z.output<T> } => { | ||
const response = MoonrakerHTTPResponse.parse(result); | ||
return { | ||
...response, | ||
result: responseZod.parse(response.result), | ||
}; | ||
}; |