Add OpenDTU Widget (#2069)

* add opendtu widget

* optimize widget

* Revert de translation files

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
pull/2074/head
Luca Kröger 1 year ago committed by GitHub
parent 588429c868
commit 64e8245542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -529,6 +529,12 @@
"streams_active": "Active Streams",
"streams_xepg": "XEPG Channels"
},
"opendtu": {
"yieldDay": "Today",
"absolutePower": "Power",
"relativePower": "Power %",
"limit": "Limit"
},
"opnsense": {
"cpu": "CPU Load",
"memory": "Active Memory",

@ -61,6 +61,7 @@ const components = {
octoprint: dynamic(() => import("./octoprint/component")),
omada: dynamic(() => import("./omada/component")),
ombi: dynamic(() => import("./ombi/component")),
opendtu: dynamic(() => import("./opendtu/component")),
opnsense: dynamic(() => import("./opnsense/component")),
overseerr: dynamic(() => import("./overseerr/component")),
openmediavault: dynamic(() => import("./openmediavault/component")),

@ -0,0 +1,48 @@
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: opendtuData, error: opendtuError } = useWidgetAPI(widget);
if (opendtuError) {
return <Container service={service} error={opendtuError} />;
}
if (!opendtuData) {
return (
<Container service={service}>
<Block label="opendtu.yieldDay" />
<Block label="opendtu.relativePower" />
<Block label="opendtu.absolutePower" />
<Block label="opendtu.limit" />
</Container>
);
}
const yieldDay = opendtuData.total.YieldDay.v
const yieldDayUnit = opendtuData.total.YieldDay.u
const power = opendtuData.total.Power.v
const powerUnit = opendtuData.total.Power.u
const totalLimit = opendtuData.inverters.map(inverter => inverter.limit_absolute).reduce((a,b) => a+b);
const totalLimitUnit = "W"
const powerPercentage = (power / totalLimit) * 100
return (
<Container service={service}>
<Block label="opendtu.yieldDay" value={`${t("common.number", { value: Math.round(yieldDay), style: "unit" })}${yieldDayUnit}`} />
<Block label="opendtu.relativePower" value={t("common.number", { value: Math.round(powerPercentage), style: "unit", unit: "percent" })} />
<Block label="opendtu.absolutePower" value={`${t("common.number", { value: Math.round(power), style: "unit" })}${powerUnit}`} />
<Block label="opendtu.limit" value={`${t("common.number", { value: Math.round(totalLimit), style: "unit" })}${totalLimitUnit}`} />
</Container>
);
}

@ -0,0 +1,8 @@
import genericProxyHandler from "utils/proxy/handlers/generic";
const widget = {
api: "{url}/api/livedata/status",
proxyHandler: genericProxyHandler,
};
export default widget;

@ -55,6 +55,7 @@ import nzbget from "./nzbget/widget";
import octoprint from "./octoprint/widget";
import omada from "./omada/widget";
import ombi from "./ombi/widget";
import opendtu from "./opendtu/widget";
import opnsense from "./opnsense/widget";
import overseerr from "./overseerr/widget";
import openmediavault from "./openmediavault/widget";
@ -156,6 +157,7 @@ const widgets = {
octoprint,
omada,
ombi,
opendtu,
opnsense,
overseerr,
openmediavault,

Loading…
Cancel
Save