You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.4 KiB
42 lines
1.4 KiB
import { useTranslation } from "next-i18next";
|
|
|
|
import Block from "components/services/widget/block";
|
|
import Container from "components/services/widget/container";
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
|
|
|
export default function Component({ service }) {
|
|
const { t } = useTranslation();
|
|
|
|
const { widget } = service;
|
|
const { data: resultData, error: resultError } = useWidgetAPI(widget);
|
|
|
|
if (resultError) {
|
|
return <Container service={service} error={resultError} />;
|
|
}
|
|
|
|
if (!resultData) {
|
|
return (
|
|
<Container service={service}>
|
|
<Block label="esphome.online" />
|
|
<Block label="esphome.offline" />
|
|
<Block label="esphome.unknown" />
|
|
<Block label="esphome.total" />
|
|
</Container>
|
|
);
|
|
}
|
|
|
|
const total = Object.keys(resultData).length;
|
|
const online = Object.entries(resultData).filter(([, v]) => v === true).length;
|
|
const offline = Object.entries(resultData).filter(([, v]) => v === false).length;
|
|
const unknown = Object.entries(resultData).filter(([, v]) => v === null).length;
|
|
|
|
return (
|
|
<Container service={service}>
|
|
<Block label="esphome.online" value={t("common.number", { value: online })} />
|
|
<Block label="esphome.offline" value={t("common.number", { value: offline })} />
|
|
<Block label="esphome.unknown" value={t("common.number", { value: unknown })} />
|
|
<Block label="esphome.total" value={t("common.number", { value: total })} />
|
|
</Container>
|
|
);
|
|
}
|