Merge pull request #834 from williamwoldum/octoPrint

OctoPrint Widget
pull/850/head
Jason Fischer 2 years ago committed by GitHub
commit 1935965095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

8518
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -423,5 +423,11 @@
"print_status": "Print Status",
"print_progress": "Progress",
"layers": "Layers"
},
"octoPrint": {
"printer_state": "Status",
"temp_tool": "Tool temp",
"temp_bed": "Bed temp",
"job_completion": "Completion"
}
}

@ -29,6 +29,7 @@ const components = {
nextdns: dynamic(() => import("./nextdns/component")),
npm: dynamic(() => import("./npm/component")),
nzbget: dynamic(() => import("./nzbget/component")),
octoPrint: dynamic(() => import("./octoPrint/component")),
omada: dynamic(() => import("./omada/component")),
ombi: dynamic(() => import("./ombi/component")),
opnsense: dynamic(() => import("./opnsense/component")),

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

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

@ -24,6 +24,7 @@ import navidrome from "./navidrome/widget";
import nextdns from "./nextdns/widget";
import npm from "./npm/widget";
import nzbget from "./nzbget/widget";
import octoPrint from "./octoPrint/widget";
import omada from "./omada/widget";
import ombi from "./ombi/widget";
import opnsense from "./opnsense/widget";
@ -51,8 +52,8 @@ import transmission from "./transmission/widget";
import tubearchivist from "./tubearchivist/widget";
import truenas from "./truenas/widget";
import unifi from "./unifi/widget";
import watchtower from './watchtower/widget'
import xteve from './xteve/widget'
import watchtower from "./watchtower/widget";
import xteve from "./xteve/widget";
const widgets = {
adguard,
@ -83,6 +84,7 @@ const widgets = {
nextdns,
npm,
nzbget,
octoPrint,
omada,
ombi,
opnsense,

Loading…
Cancel
Save