From d3e77a102543ae4c1dd743186d81b44740e5518f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20Kr=C3=B6ger?= Date: Sun, 24 Sep 2023 11:31:20 +0200 Subject: [PATCH] add opendtu widget --- public/locales/de/common.json | 5 ++++ public/locales/en/common.json | 5 ++++ src/widgets/components.js | 1 + src/widgets/opendtu/component.jsx | 45 +++++++++++++++++++++++++++++++ src/widgets/opendtu/widget.js | 8 ++++++ src/widgets/widgets.js | 2 ++ 6 files changed, 66 insertions(+) create mode 100644 src/widgets/opendtu/component.jsx create mode 100644 src/widgets/opendtu/widget.js diff --git a/public/locales/de/common.json b/public/locales/de/common.json index 704bb2c9..82164d8b 100644 --- a/public/locales/de/common.json +++ b/public/locales/de/common.json @@ -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", diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 9a6da7a4..b0ce60d7 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -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", diff --git a/src/widgets/components.js b/src/widgets/components.js index 4ed79044..66044406 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -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")), diff --git a/src/widgets/opendtu/component.jsx b/src/widgets/opendtu/component.jsx new file mode 100644 index 00000000..d9cad1a2 --- /dev/null +++ b/src/widgets/opendtu/component.jsx @@ -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 ; + } + + if (!opendtuLiveData) { + return ( + + + + + + ); + } + + 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 ( + + + + + + ); +} diff --git a/src/widgets/opendtu/widget.js b/src/widgets/opendtu/widget.js new file mode 100644 index 00000000..f0ac2cc6 --- /dev/null +++ b/src/widgets/opendtu/widget.js @@ -0,0 +1,8 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/api/livedata/status", + proxyHandler: genericProxyHandler, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index a2b97dd3..6bc682da 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -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,