Wall displays: a night schedule that dims or blanks the board
A named display can dim the board or blank it (so a tablet or computer may sleep) between two times on the screen's own clock. A critical alert brings the board back unless told not to, and a touch or key press brings it back for two minutes. A share link that opens the display follows the same schedule. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
168d01dc7b
commit
a69d0a611d
17 files changed
+9948
-22
No files matched your search
@@ -96,6 +96,49 @@ describe("what a display shows, and how fast", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("the night", () => {
|
||||
const at = (hh: number, mm = 0) => new Date(2026, 10, 10, hh, mm, 0);
|
||||
const night = { from: "22:00", to: "07:00", mode: "dim" as const, wakeOnCritical: true };
|
||||
|
||||
test("a night across midnight is from the start up to, not including, the end; one within a day is plain", () => {
|
||||
assert.equal(P.inNight(at(21, 59), night), false);
|
||||
assert.equal(P.inNight(at(22, 0), night), true);
|
||||
assert.equal(P.inNight(at(23, 59), night), true);
|
||||
assert.equal(P.inNight(at(0, 0), night), true);
|
||||
assert.equal(P.inNight(at(6, 59), night), true);
|
||||
assert.equal(P.inNight(at(7, 0), night), false, "the end is the morning");
|
||||
assert.equal(P.inNight(at(12, 0), night), false);
|
||||
const nap = { from: "13:00", to: "15:30" };
|
||||
assert.deepEqual([at(12, 59), at(13, 0), at(15, 29), at(15, 30)].map((d) => P.inNight(d, nap)), [false, true, true, false]);
|
||||
assert.equal(P.inNight(at(3), { from: "05:00", to: "05:00" }), false, "no length, no night");
|
||||
});
|
||||
|
||||
test("at night it is dimmed or blank; by day, with no schedule, or when something is critical (if told to) it is the board", () => {
|
||||
const quiet = { critical: false, wokenUntil: null };
|
||||
assert.equal(P.nightState(at(12), night, quiet), "day");
|
||||
assert.equal(P.nightState(at(23), night, quiet), "dim");
|
||||
assert.equal(P.nightState(at(23), { ...night, mode: "off" }, quiet), "off");
|
||||
assert.equal(P.nightState(at(23), null, quiet), "day");
|
||||
assert.equal(P.nightState(at(23), undefined, quiet), "day");
|
||||
assert.equal(P.nightState(at(23), night, { critical: true, wokenUntil: null }), "day", "something is critical");
|
||||
assert.equal(P.nightState(at(23), { ...night, mode: "off", wakeOnCritical: false }, { critical: true, wokenUntil: null }), "off", "told not to");
|
||||
});
|
||||
|
||||
test("a touch brings the board back for two minutes, then the night returns", () => {
|
||||
const now = at(23);
|
||||
const touched = now.getTime() + P.WAKE_FOR_MS;
|
||||
assert.equal(P.WAKE_FOR_MS, 120_000);
|
||||
assert.equal(P.nightState(now, night, { critical: false, wokenUntil: touched }), "day");
|
||||
assert.equal(P.nightState(new Date(touched + 1), night, { critical: false, wokenUntil: touched }), "dim");
|
||||
});
|
||||
|
||||
test("what is stored is a night only when all of it is there and makes sense", () => {
|
||||
const row = { nightFrom: "22:00", nightTo: "07:00", nightMode: "off", nightWakeCritical: false };
|
||||
assert.deepEqual(W.nightOf(row), { from: "22:00", to: "07:00", mode: "off", wakeOnCritical: false });
|
||||
for (const bad of [{ nightFrom: null }, { nightTo: null }, { nightMode: null }, { nightFrom: "7:00" }, { nightTo: "24:00" }, { nightMode: "sleep" }, { nightTo: "22:00" }]) assert.equal(W.nightOf({ ...row, ...bad }), null, JSON.stringify(bad));
|
||||
});
|
||||
});
|
||||
|
||||
describe("the routes", () => {
|
||||
let app: Server;
|
||||
let base = "";
|
||||
@@ -184,7 +227,7 @@ describe("the routes", () => {
|
||||
assert.equal(link.displayId, id);
|
||||
|
||||
const board = await (await call("GET", `/public/wall/${token}`)).json();
|
||||
assert.deepEqual(board.displayConfig, { name: "Hall TV", pages: ["overview", "group:apps"], rotateSeconds: 30 });
|
||||
assert.deepEqual(board.displayConfig, { name: "Hall TV", pages: ["overview", "group:apps"], rotateSeconds: 30, night: null });
|
||||
|
||||
// a link with no display says none
|
||||
const plain = (await (await call("POST", "/share-links", { label: "Whole board", kind: "wall", expiresInDays: null })).json()).token;
|
||||
@@ -216,6 +259,33 @@ describe("the routes", () => {
|
||||
assert.equal(describeChange("wall_display", "delete", { name: "Hall TV" }).title, "Wall display removed: Hall TV");
|
||||
});
|
||||
|
||||
test("a display can have a night schedule; it is read back, given to the public board, and taken away by saving without one", async () => {
|
||||
const made = await call("POST", "/wall-displays", { name: "Bedroom", night: { from: "23:00", to: "06:30", mode: "off", wakeOnCritical: false } });
|
||||
assert.equal(made.status, 201);
|
||||
const display = (await made.json()).display;
|
||||
assert.deepEqual(display.night, { from: "23:00", to: "06:30", mode: "off", wakeOnCritical: false });
|
||||
|
||||
const link = await (await call("POST", "/share-links", { label: "Bedroom screen", kind: "wall", displayId: display.id, expiresInDays: null })).json();
|
||||
const board = await (await call("GET", `/public/wall/${link.token}`)).json();
|
||||
assert.deepEqual(board.displayConfig.night, { from: "23:00", to: "06:30", mode: "off", wakeOnCritical: false });
|
||||
|
||||
const without = (await (await call("PUT", `/wall-displays/${display.id}`, { name: "Bedroom" })).json()).display;
|
||||
assert.equal(without.night, null);
|
||||
assert.equal((await (await call("GET", `/public/wall/${link.token}`)).json()).displayConfig.night, null);
|
||||
|
||||
const defaults = (await (await call("PUT", `/wall-displays/${display.id}`, { name: "Bedroom", night: { from: "22:00", to: "07:00", mode: "dim" } })).json()).display;
|
||||
assert.equal(defaults.night.wakeOnCritical, true, "a critical alert brings it back unless it is told not to");
|
||||
await call("DELETE", `/wall-displays/${display.id}`);
|
||||
});
|
||||
|
||||
test("a night needs real times, two that differ, and a way", async () => {
|
||||
const bad = (night: unknown) => call("POST", "/wall-displays", { name: "Nope", night });
|
||||
for (const n of [{ from: "7:00", to: "22:00", mode: "dim" }, { from: "22:00", to: "25:00", mode: "dim" }, { from: "22:00", to: "22:00", mode: "dim" }, { from: "22:00", to: "07:00", mode: "sleep" }, { from: "22:00", to: "07:00" }, { from: "22:00" }, "night"]) {
|
||||
assert.equal((await bad(n)).status, 400, JSON.stringify(n));
|
||||
}
|
||||
assert.match((await (await bad({ from: "22:00", to: "22:00", mode: "dim" })).json()).message, /start and an end that differ/);
|
||||
});
|
||||
|
||||
test("no more than twenty", async () => {
|
||||
for (let i = 0; i < 25; i++) {
|
||||
const r = await call("POST", "/wall-displays", { name: `Screen ${i}` });
|
||||
|
||||
Reference in new issue
Block a user