2022-10-24 16:40:49 -03: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";
|
|
|
|
|
|
|
|
export default function Component({ service }) {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
const { widget } = service;
|
|
|
|
|
|
|
|
const { data: homebridge, error: homebridgeError } = useWidgetAPI(widget, "info");
|
|
|
|
|
|
|
|
if (homebridgeError || (homebridge && !homebridge.data)) {
|
|
|
|
return <Container error={t("widget.api_error")} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!homebridge) {
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="widget.status" />
|
2022-10-24 18:09:48 -03:00
|
|
|
<Block label="homebridge.updates" />
|
|
|
|
<Block label="homebridge.child_bridges" />
|
2022-10-24 16:40:49 -03:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block
|
|
|
|
label="widget.status"
|
2022-10-24 14:27:31 -07:00
|
|
|
value={`${homebridge.data.status[0].toUpperCase()}${homebridge.data.status.substr(1)}`}
|
2022-10-24 16:40:49 -03:00
|
|
|
/>
|
|
|
|
<Block
|
2022-10-24 18:09:48 -03:00
|
|
|
label="homebridge.updates"
|
|
|
|
value={
|
|
|
|
(homebridge.data.updateAvailable || homebridge.data.plugins.updatesAvailable)
|
|
|
|
? t("homebridge.update_available")
|
|
|
|
: t("homebridge.up_to_date")}
|
2022-10-24 16:40:49 -03:00
|
|
|
/>
|
2022-10-24 18:09:48 -03:00
|
|
|
{homebridge?.data?.childBridges.quantity > 0 &&
|
|
|
|
<Block
|
|
|
|
label="homebridge.child_bridges"
|
|
|
|
value={t("homebridge.child_bridges_status", {
|
|
|
|
total: homebridge.data.childBridges.quantity,
|
|
|
|
ok: homebridge.data.childBridges.quantityWithOkStatus
|
|
|
|
})}
|
|
|
|
/>}
|
2022-10-24 16:40:49 -03:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|