-
-
Notifications
You must be signed in to change notification settings - Fork 972
/
component.jsx
53 lines (45 loc) · 1.53 KB
/
component.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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: homebridgeData, error: homebridgeError } = useWidgetAPI(widget, "info");
console.log(homebridgeData);
if (homebridgeError || homebridgeData?.error) {
return <Container error={t("widget.api_error")} />;
}
if (!homebridgeData) {
return (
<Container service={service}>
<Block label="widget.status" />
<Block label="homebridge.updates" />
<Block label="homebridge.child_bridges" />
</Container>
);
}
return (
<Container service={service}>
<Block
label="widget.status"
value={`${homebridgeData.status[0].toUpperCase()}${homebridgeData.status.substr(1)}`}
/>
<Block
label="homebridge.updates"
value={
(homebridgeData.updateAvailable || homebridgeData.plugins?.updatesAvailable)
? t("homebridge.update_available")
: t("homebridge.up_to_date")}
/>
{homebridgeData?.childBridges?.total > 0 &&
<Block
label="homebridge.child_bridges"
value={t("homebridge.child_bridges_status", {
total: homebridgeData.childBridges.total,
ok: homebridgeData.childBridges.running
})}
/>}
</Container>
);
}