-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49281b3
commit e87180b
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters