2023-01-17 03:54:24 +01:00
|
|
|
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", {
|
|
|
|
refreshInterval: 1500,
|
|
|
|
});
|
|
|
|
const { data: jobStats, error: jobStatsError } = useWidgetAPI(widget, "job_stats", {
|
|
|
|
refreshInterval: 1500,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (printerStatsError) {
|
|
|
|
return <Container error={printerStatsError} />;
|
|
|
|
}
|
|
|
|
|
2023-01-17 23:08:58 +01:00
|
|
|
if (jobStatsError) {
|
|
|
|
return <Container error={jobStatsError} />;
|
2023-01-17 03:54:24 +01:00
|
|
|
}
|
|
|
|
|
2023-01-17 23:08:58 +01:00
|
|
|
const state = printerStats?.state?.text;
|
|
|
|
const tempTool = printerStats?.temperature?.tool0?.actual;
|
|
|
|
const tempBed = printerStats?.temperature?.bed?.actual;
|
2023-01-17 12:50:08 +01:00
|
|
|
|
2023-01-17 23:08:58 +01:00
|
|
|
if (!printerStats || !state || !tempTool || !tempBed) {
|
2023-01-17 03:54:24 +01:00
|
|
|
return (
|
|
|
|
<Container service={service}>
|
2023-01-17 23:08:58 +01:00
|
|
|
<Block label="octoPrint.printer_state" />
|
2023-01-17 03:54:24 +01:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-18 00:47:51 +01:00
|
|
|
const printingStateFalgs = ["Printing", "Paused", "Pausing", "Resuming"];
|
|
|
|
|
|
|
|
if (printingStateFalgs.includes(state)) {
|
2023-01-17 23:08:58 +01:00
|
|
|
const { completion } = jobStats.progress;
|
2023-01-17 12:50:08 +01:00
|
|
|
|
2023-01-17 23:08:58 +01:00
|
|
|
if (!jobStats || !completion) {
|
2023-01-17 03:54:24 +01:00
|
|
|
return (
|
|
|
|
<Container service={service}>
|
2023-01-17 23:08:58 +01:00
|
|
|
<Block label="octoPrint.printer_state" />
|
|
|
|
<Block label="octoPrint.temp_tool" />
|
|
|
|
<Block label="octoPrint.temp_bed" />
|
2023-01-17 03:54:24 +01:00
|
|
|
<Block label="octoPrint.job_completion" />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-01-17 23:08:58 +01:00
|
|
|
<Container service={service}>
|
|
|
|
<Block label="octoPrint.printer_state" value={printerStats.state.text} />
|
|
|
|
<Block label="octoPrint.temp_tool" value={`${printerStats.temperature.tool0.actual}°`} />
|
|
|
|
<Block label="octoPrint.temp_bed" value={`${printerStats.temperature.bed.actual}°`} />
|
|
|
|
<Block label="octoPrint.job_completion" value={`${completion.toFixed(2)}%`} />
|
|
|
|
</Container>
|
2023-01-17 03:54:24 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="octoPrint.printer_state" value={printerStats.state.text} />
|
|
|
|
<Block label="octoPrint.temp_tool" value={`${printerStats.temperature.tool0.actual}°`} />
|
|
|
|
<Block label="octoPrint.temp_bed" value={`${printerStats.temperature.bed.actual}°`} />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|