add opendtu widget
This commit is contained in:
parent
63a47b1ad2
commit
d3e77a1025
@ -447,6 +447,11 @@
|
||||
"streams_active": "Aktive Streams",
|
||||
"streams_xepg": "XEPG Kanäle"
|
||||
},
|
||||
"opendtu": {
|
||||
"absoluteGeneration": "Gesamterzeugung",
|
||||
"relativeGeneration": "Gesamterzeugung %",
|
||||
"limit": "Limit"
|
||||
},
|
||||
"opnsense": {
|
||||
"cpu": "CPU Auslastung",
|
||||
"memory": "Aktiver RAM",
|
||||
|
||||
@ -529,6 +529,11 @@
|
||||
"streams_active": "Active Streams",
|
||||
"streams_xepg": "XEPG Channels"
|
||||
},
|
||||
"opendtu": {
|
||||
"relativeGeneration": "Power Generation %",
|
||||
"absoluteGeneration": "Power Generation",
|
||||
"limit": "Power 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")),
|
||||
|
||||
45
src/widgets/opendtu/component.jsx
Normal file
45
src/widgets/opendtu/component.jsx
Normal file
@ -0,0 +1,45 @@
|
||||
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: opendtuLiveData, error: opendtuError } = useWidgetAPI(widget);
|
||||
|
||||
if (opendtuError) {
|
||||
return <Container service={service} error={opendtuError} />;
|
||||
}
|
||||
|
||||
if (!opendtuLiveData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="opendtu.relativeGeneration" />
|
||||
<Block label="opendtu.totalGeneration" />
|
||||
<Block label="opendtu.limit" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const totalGeneration = opendtuLiveData.inverters.map(inverter =>
|
||||
Object.values(inverter.AC).map(
|
||||
AC => AC.Power.v
|
||||
).reduce((a,b) => a+b))
|
||||
.reduce((a,b) => a+b);
|
||||
|
||||
const totalLimit = opendtuLiveData.inverters.map(inverter => inverter.limit_absolute).reduce((a,b) => a+b);
|
||||
|
||||
const usagePercentage = (totalGeneration / totalLimit) * 100
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="opendtu.relativeGeneration" value={t("common.number", { value: Math.round(usagePercentage), style: "unit", unit: "percent" })} />
|
||||
<Block label="opendtu.totalGeneration" value={`${t("common.number", { value: Math.round(totalGeneration), style: "unit"})}W`} />
|
||||
<Block label="opendtu.limit" value={`${t("common.number", { value: Math.round(totalLimit), style: "unit"})}W`} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
8
src/widgets/opendtu/widget.js
Normal file
8
src/widgets/opendtu/widget.js
Normal file
@ -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…
Reference in New Issue
Block a user