2023-05-17 19:39:15 +02:00
|
|
|
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";
|
|
|
|
|
2024-12-10 08:36:32 -08:00
|
|
|
function toKilowatts(t, value) {
|
|
|
|
return value > 0 ? t("common.number", { value: value / 1000, maximumFractionDigits: 1 }) : 0;
|
|
|
|
}
|
|
|
|
|
2023-05-17 19:39:15 +02:00
|
|
|
export default function Component({ service }) {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
const { widget } = service;
|
|
|
|
const { data: stateData, error: stateError } = useWidgetAPI(widget, "state");
|
|
|
|
|
|
|
|
if (stateError) {
|
|
|
|
return <Container service={service} error={stateError} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stateData) {
|
|
|
|
return (
|
2023-10-17 23:26:55 -07:00
|
|
|
<Container service={service}>
|
2023-05-17 19:39:15 +02:00
|
|
|
<Block label="evcc.pv_power" />
|
|
|
|
<Block label="evcc.grid_power" />
|
|
|
|
<Block label="evcc.home_power" />
|
2023-10-17 23:26:55 -07:00
|
|
|
<Block label="evcc.charge_power" />
|
2023-05-17 19:39:15 +02:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-01-20 07:55:26 -08:00
|
|
|
// broken by evcc v0.133.0 https://github.com/evcc-io/evcc/commit/9dcb1fa0a7c08dd926b79309aa1f676a5fc6c8aa
|
|
|
|
const gridPower = stateData.result.gridPower ?? stateData.result.grid?.power ?? 0;
|
|
|
|
|
2023-05-17 19:39:15 +02:00
|
|
|
return (
|
|
|
|
<Container service={service}>
|
2024-12-10 08:36:32 -08:00
|
|
|
<Block label="evcc.pv_power" value={`${toKilowatts(t, stateData.result.pvPower)} ${t("evcc.kilowatt")}`} />
|
2025-01-20 07:55:26 -08:00
|
|
|
<Block label="evcc.grid_power" value={`${toKilowatts(t, gridPower)} ${t("evcc.kilowatt")}`} />
|
2024-12-10 08:36:32 -08:00
|
|
|
<Block label="evcc.home_power" value={`${toKilowatts(t, stateData.result.homePower)} ${t("evcc.kilowatt")}`} />
|
2023-10-17 23:26:55 -07:00
|
|
|
<Block
|
|
|
|
label="evcc.charge_power"
|
2024-12-10 08:36:32 -08:00
|
|
|
value={`${toKilowatts(t, stateData.result.loadpoints[0].chargePower)} ${t("evcc.kilowatt")}`}
|
2023-10-17 23:26:55 -07:00
|
|
|
/>
|
2023-05-17 19:39:15 +02:00
|
|
|
</Container>
|
|
|
|
);
|
2023-10-17 23:26:55 -07:00
|
|
|
}
|