Fix: better handle PeaNUT missing data (#7139)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled

This commit is contained in:
shamoon
2026-09-12 21:49:05 -07:00
committed by GitHub
parent fcd9a715d9
commit c764d05a0c
2 changed files with 16 additions and 7 deletions
+5 -7
View File
@@ -41,17 +41,15 @@ export default function Component({ service }) {
status = t("peanut.low_battery"); status = t("peanut.low_battery");
break; break;
default: default:
status = upsStatus; status = typeof upsStatus === "string" && upsStatus ? upsStatus : "-";
} }
const percent = (value) => (value === undefined || value === null ? "-" : t("common.percent", { value }));
return ( return (
<Container service={service}> <Container service={service}>
<Block <Block label="peanut.battery_charge" value={percent(batteryCharge)} highlightValue={batteryCharge} />
label="peanut.battery_charge" <Block label="peanut.ups_load" value={percent(upsLoad)} highlightValue={upsLoad} />
value={t("common.percent", { value: batteryCharge })}
highlightValue={batteryCharge}
/>
<Block label="peanut.ups_load" value={t("common.percent", { value: upsLoad })} highlightValue={upsLoad} />
<Block label="peanut.ups_status" value={status} /> <Block label="peanut.ups_status" value={status} />
</Container> </Container>
); );
+11
View File
@@ -51,4 +51,15 @@ describe("widgets/peanut/component", () => {
expect(screen.getByText("peanut.online")).toBeInTheDocument(); expect(screen.getByText("peanut.online")).toBeInTheDocument();
expect(data).toEqual({ "battery.charge": 55, "ups.load": 12, "ups.status": "OL" }); expect(data).toEqual({ "battery.charge": 55, "ups.load": 12, "ups.status": "OL" });
}); });
it("renders dashes when readings are missing", () => {
useWidgetAPI.mockReturnValue({
data: { "device.model": "OR500LCDRM1Ua", "ups.status": 0 },
error: undefined,
});
renderWithProviders(<Component service={{ widget: { type: "peanut" } }} />, { settings: { hideErrors: false } });
expect(screen.getAllByText("-")).toHaveLength(3);
});
}); });