optimize widget
This commit is contained in:
parent
d3e77a1025
commit
4bdee0ff91
@ -448,8 +448,9 @@
|
|||||||
"streams_xepg": "XEPG Kanäle"
|
"streams_xepg": "XEPG Kanäle"
|
||||||
},
|
},
|
||||||
"opendtu": {
|
"opendtu": {
|
||||||
"absoluteGeneration": "Gesamterzeugung",
|
"yieldDay": "Heute",
|
||||||
"relativeGeneration": "Gesamterzeugung %",
|
"absolutePower": "Produktion",
|
||||||
|
"relativePower": "Produktion %",
|
||||||
"limit": "Limit"
|
"limit": "Limit"
|
||||||
},
|
},
|
||||||
"opnsense": {
|
"opnsense": {
|
||||||
|
|||||||
@ -530,9 +530,10 @@
|
|||||||
"streams_xepg": "XEPG Channels"
|
"streams_xepg": "XEPG Channels"
|
||||||
},
|
},
|
||||||
"opendtu": {
|
"opendtu": {
|
||||||
"relativeGeneration": "Power Generation %",
|
"yieldDay": "Today",
|
||||||
"absoluteGeneration": "Power Generation",
|
"absolutePower": "Power",
|
||||||
"limit": "Power Limit"
|
"relativePower": "Power %",
|
||||||
|
"limit": "Limit"
|
||||||
},
|
},
|
||||||
"opnsense": {
|
"opnsense": {
|
||||||
"cpu": "CPU Load",
|
"cpu": "CPU Load",
|
||||||
|
|||||||
@ -9,37 +9,40 @@ export default function Component({ service }) {
|
|||||||
|
|
||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
|
|
||||||
const { data: opendtuLiveData, error: opendtuError } = useWidgetAPI(widget);
|
const { data: opendtuData, error: opendtuError } = useWidgetAPI(widget);
|
||||||
|
|
||||||
if (opendtuError) {
|
if (opendtuError) {
|
||||||
return <Container service={service} error={opendtuError} />;
|
return <Container service={service} error={opendtuError} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opendtuLiveData) {
|
if (!opendtuData) {
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="opendtu.relativeGeneration" />
|
<Block label="opendtu.yieldDay" />
|
||||||
<Block label="opendtu.totalGeneration" />
|
<Block label="opendtu.relativePower" />
|
||||||
|
<Block label="opendtu.absolutePower" />
|
||||||
<Block label="opendtu.limit" />
|
<Block label="opendtu.limit" />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalGeneration = opendtuLiveData.inverters.map(inverter =>
|
const yieldDay = opendtuData.total.YieldDay.v
|
||||||
Object.values(inverter.AC).map(
|
const yieldDayUnit = opendtuData.total.YieldDay.u
|
||||||
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
|
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 (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="opendtu.relativeGeneration" value={t("common.number", { value: Math.round(usagePercentage), style: "unit", unit: "percent" })} />
|
<Block label="opendtu.yieldDay" value={`${t("common.number", { value: Math.round(yieldDay), style: "unit" })}${yieldDayUnit}`} />
|
||||||
<Block label="opendtu.totalGeneration" value={`${t("common.number", { value: Math.round(totalGeneration), style: "unit"})}W`} />
|
<Block label="opendtu.relativePower" value={t("common.number", { value: Math.round(powerPercentage), style: "unit", unit: "percent" })} />
|
||||||
<Block label="opendtu.limit" value={`${t("common.number", { value: Math.round(totalLimit), style: "unit"})}W`} />
|
<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>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user