mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-17 02:09:49 +00:00
Remove capital from octoprint widget
remove add
This commit is contained in:
parent
01eea51555
commit
d27b795d81
5 changed files with 16 additions and 16 deletions
64
src/widgets/octoprint/component.jsx
Normal file
64
src/widgets/octoprint/component.jsx
Normal file
|
@ -0,0 +1,64 @@
|
|||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { widget } = service;
|
||||
|
||||
const { data: printerStats, error: printerStatsError } = useWidgetAPI(widget, "printer_stats");
|
||||
const { data: jobStats, error: jobStatsError } = useWidgetAPI(widget, "job_stats");
|
||||
|
||||
if (printerStatsError) {
|
||||
return <Container error={printerStatsError} />;
|
||||
}
|
||||
|
||||
if (jobStatsError) {
|
||||
return <Container error={jobStatsError} />;
|
||||
}
|
||||
|
||||
const state = printerStats?.state?.text;
|
||||
const tempTool = printerStats?.temperature?.tool0?.actual;
|
||||
const tempBed = printerStats?.temperature?.bed?.actual;
|
||||
|
||||
if (!printerStats || !state || !tempTool || !tempBed) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="octoprint.printer_state" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const printingStateFalgs = ["Printing", "Paused", "Pausing", "Resuming"];
|
||||
|
||||
if (printingStateFalgs.includes(state)) {
|
||||
const { completion } = jobStats.progress;
|
||||
|
||||
if (!jobStats || !completion) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="octoprint.printer_state" />
|
||||
<Block label="octoprint.temp_tool" />
|
||||
<Block label="octoprint.temp_bed" />
|
||||
<Block label="octoprint.job_completion" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="octoprint.printer_state" value={printerStats.state.text} />
|
||||
<Block label="octoprint.temp_tool" value={`${printerStats.temperature.tool0.actual} °C`} />
|
||||
<Block label="octoprint.temp_bed" value={`${printerStats.temperature.bed.actual} °C`} />
|
||||
<Block label="octoprint.job_completion" value={`${completion.toFixed(2)}%`} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="octoprint.printer_state" value={printerStats.state.text} />
|
||||
<Block label="octoprint.temp_tool" value={`${printerStats.temperature.tool0.actual} °C`} />
|
||||
<Block label="octoprint.temp_bed" value={`${printerStats.temperature.bed.actual} °C`} />
|
||||
</Container>
|
||||
);
|
||||
}
|
17
src/widgets/octoprint/widget.js
Normal file
17
src/widgets/octoprint/widget.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/{endpoint}?apikey={key}",
|
||||
proxyHandler: genericProxyHandler,
|
||||
|
||||
mappings: {
|
||||
printer_stats: {
|
||||
endpoint: "printer",
|
||||
},
|
||||
job_stats: {
|
||||
endpoint: "job",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
Loading…
Add table
Add a link
Reference in a new issue