Initial SolarEdge Optimizer Home Assistant App

This commit is contained in:
2026-08-10 09:04:35 +02:00
commit f2887a0ab4
38 changed files with 4253 additions and 0 deletions
@@ -0,0 +1,49 @@
import { describe, expect, it } from "bun:test";
import { parseAppOptions, resolveHomeAssistantTimeZone } from "./config";
describe("SolarEdge Optimizer Data App config", () => {
it("parses the required Home Assistant App options", () => {
expect(
parseAppOptions({
username: " owner@example.com ",
password: "portal-secret",
site_id: "4886699",
poll_interval_minutes: 10,
}),
).toEqual({
username: "owner@example.com",
password: "portal-secret",
siteId: "4886699",
pollIntervalMinutes: 10,
});
});
it("rejects missing credentials and unsafe polling intervals", () => {
expect(() =>
parseAppOptions({ password: "secret", site_id: "42" }),
).toThrow("username");
expect(() =>
parseAppOptions({
username: "owner@example.com",
password: "secret",
site_id: "42",
poll_interval_minutes: 5,
}),
).toThrow("10 to 1440");
});
it("reads the Home Assistant time zone from the Supervisor", async () => {
const timeZone = await resolveHomeAssistantTimeZone({
supervisorToken: "supervisor-token",
fetchImplementation: async (input, init) => {
expect(String(input)).toBe("http://supervisor/info");
expect(new Headers(init?.headers).get("authorization")).toBe(
"Bearer supervisor-token",
);
return Response.json({ data: { timezone: "Europe/Berlin" } });
},
});
expect(timeZone).toBe("Europe/Berlin");
});
});