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;
|
|
|
|
|
2022-10-24 14:46:22 -07:00
|
|
|
const { data: homebridgeData, error: homebridgeError } = useWidgetAPI(widget, "info");
|
2022-10-24 16:40:49 -03:00
|
|
|
|
2022-10-24 14:46:22 -07:00
|
|
|
if (homebridgeError || homebridgeData?.error) {
|
2022-10-26 08:35:38 -07:00
|
|
|
const finalError = homebridgeError ?? homebridgeData.error;
|
|
|
|
return <Container error={finalError} />;
|
2022-10-24 16:40:49 -03:00
|
|
|
}
|
|
|
|
|
2022-10-24 14:46:22 -07:00
|
|
|
if (!homebridgeData) {
|
2022-10-24 16:40:49 -03:00
|
|
|
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:46:22 -07:00
|
|
|
value={`${homebridgeData.status[0].toUpperCase()}${homebridgeData.status.substr(1)}`}
|
2022-10-24 16:40:49 -03:00
|
|
|
/>
|
|
|
|
<Block
|
2022-10-24 18:09:48 -03:00
|
|
|
label="homebridge.updates"
|
|
|
|
value={
|
2022-10-24 14:46:22 -07:00
|
|
|
(homebridgeData.updateAvailable || homebridgeData.plugins?.updatesAvailable)
|
2022-10-24 18:09:48 -03:00
|
|
|
? t("homebridge.update_available")
|
|
|
|
: t("homebridge.up_to_date")}
|
2022-10-24 16:40:49 -03:00
|
|
|
/>
|
2022-10-24 14:46:22 -07:00
|
|
|
{homebridgeData?.childBridges?.total > 0 &&
|
2022-10-24 18:09:48 -03:00
|
|
|
<Block
|
|
|
|
label="homebridge.child_bridges"
|
|
|
|
value={t("homebridge.child_bridges_status", {
|
2022-10-24 14:46:22 -07:00
|
|
|
total: homebridgeData.childBridges.total,
|
|
|
|
ok: homebridgeData.childBridges.running
|
2022-10-24 18:09:48 -03:00
|
|
|
})}
|
|
|
|
/>}
|
2022-10-24 16:40:49 -03:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|