Skip to content

Commit

Permalink
add peanut widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandawg93 committed Dec 9, 2023
1 parent 49281b3 commit e87180b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@
"inbox": "Inbox",
"total": "Total"
},
"peanut": {
"battery_charge": "Battery Charge",
"ups_load": "UPS Load",
"ups_status": "UPS Status",
"online": "Online",
"on_battery": "On Battery",
"low_battery": "Low Battery"
},
"nextdns": {
"wait": "Please Wait",
"no_devices": "No Device Data Received"
Expand Down
1 change: 1 addition & 0 deletions src/widgets/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const components = {
gotify: dynamic(() => import("./gotify/component")),
grafana: dynamic(() => import("./grafana/component")),
hdhomerun: dynamic(() => import("./hdhomerun/component")),
peanut: dynamic(() => import("./peanut/component")),
homeassistant: dynamic(() => import("./homeassistant/component")),
homebridge: dynamic(() => import("./homebridge/component")),
healthchecks: dynamic(() => import("./healthchecks/component")),
Expand Down
50 changes: 50 additions & 0 deletions src/widgets/peanut/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 { widget } = service;
const { t } = useTranslation();

const { data: upsData, error: upsError } = useWidgetAPI(widget, "devices");

if (upsError) {
return <Container service={service} error={upsError} />;
}

if (!upsData) {
return (
<Container service={service}>
<Block label="peanut.battery_charge" />
<Block label="peanut.ups_load" />
<Block label="peanut.ups_status" />
</Container>
);
}

let status;
switch (upsData.ups_status) {
case "OL":
status = t("peanut.online");
break;
case "OB":
status = t("peanut.on_battery");
break;
case "LB":
status = t("peanut.low_battery");
break;
default:
status = upsData.ups_status;
}

return (
<Container service={service}>
<Block label="peanut.battery_charge" value={`${upsData.battery_charge}%`} />
<Block label="peanut.ups_load" value={`${upsData.ups_load}%`} />
<Block label="peanut.ups_status" value={status} />
</Container>
);
}
14 changes: 14 additions & 0 deletions src/widgets/peanut/widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import genericProxyHandler from "utils/proxy/handlers/generic";

const widget = {
api: "{url}/api/v1/{endpoint}/{key}",
proxyHandler: genericProxyHandler,

mappings: {
devices: {
endpoint: "devices",
},
},
};

export default widget;
2 changes: 2 additions & 0 deletions src/widgets/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import opnsense from "./opnsense/widget";
import overseerr from "./overseerr/widget";
import openmediavault from "./openmediavault/widget";
import paperlessngx from "./paperlessngx/widget";
import peanut from "./peanut/widget";
import pfsense from "./pfsense/widget";
import photoprism from "./photoprism/widget";
import proxmoxbackupserver from "./proxmoxbackupserver/widget";
Expand Down Expand Up @@ -166,6 +167,7 @@ const widgets = {
overseerr,
openmediavault,
paperlessngx,
peanut,
pfsense,
photoprism,
proxmoxbackupserver,
Expand Down

0 comments on commit e87180b

Please sign in to comment.