Add Moonraker (Klipper) widget (#798)
* Add Moonraker (Klipper) widget * Fix linting * Removed filename, to adhere to standards * Removed unused translation * fix conditional in moonraker component Co-authored-by: Eizock <> Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>pull/817/head
parent
a04c7677e4
commit
0febf05d8d
@ -0,0 +1,51 @@
|
|||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
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 { t } = useTranslation();
|
||||||
|
|
||||||
|
const { widget } = service;
|
||||||
|
|
||||||
|
const { data: printStats, error: printStatsError } = useWidgetAPI(widget, "print_stats");
|
||||||
|
const { data: displayStatus, error: displayStatsError } = useWidgetAPI(widget, "display_status");
|
||||||
|
const { data: webHooks, error: webHooksError } = useWidgetAPI(widget, "webhooks");
|
||||||
|
|
||||||
|
if (printStatsError || displayStatsError || webHooksError) {
|
||||||
|
const finalError = printStatsError ?? displayStatsError ?? webHooksError;
|
||||||
|
return <Container error={finalError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!printStats || !displayStatus || !webHooks) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="moonraker.printer_state" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (webHooks.result.status.webhooks.state === "shutdown") {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="moonraker.printer_state" value={webHooks.result.status.webhooks.state} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentLayer = "-";
|
||||||
|
let totalLayer = "-";
|
||||||
|
if (printStats.result.status.print_stats.info.total_layer !== null) {
|
||||||
|
currentLayer = printStats.result.status.print_stats.info.current_layer;
|
||||||
|
totalLayer = printStats.result.status.print_stats.info.total_layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="moonraker.layers" value={`${currentLayer} / ${totalLayer}`} />
|
||||||
|
<Block label="moonraker.print_progress" value={t("common.percent", { value: (displayStatus.result.status.display_status.progress * 100) })} />
|
||||||
|
<Block label="moonraker.print_status" value={printStats.result.status.print_stats.state} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/printer/objects/query?{endpoint}",
|
||||||
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
print_stats: {
|
||||||
|
endpoint: "print_stats",
|
||||||
|
},
|
||||||
|
display_status: {
|
||||||
|
endpoint: "display_status",
|
||||||
|
},
|
||||||
|
webhooks: {
|
||||||
|
endpoint: "webhooks",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
Loading…
Reference in new issue