diff --git a/README.md b/README.md index 8408bb2..745ad5c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ A Home Assistant dashboard card to view and edit the weekly time programs of a V - **Heating zones 1–3, hot water and circulation**, each on its own tab - **Edit several days at once**: quick selection for Mo–Fr, Sa–Su or all days -- **Up to 3 slots per day** in 10-minute steps, with a temperature per slot +- **Up to 12 slots per day** for heating zones, 3 for hot water and circulation, in 10-minute steps, with a + temperature per slot - **Checks before writing**: overlaps, end before start, temperatures out of range - **Verified writes**: every day is read back from the controller; retry, continue or restore if one doesn't match - **Read-only preview mode** for a compact week overview, with a marker for the current time @@ -35,7 +36,7 @@ The card needs a working ebusd setup first. Hardware and configuration all come [ebusd wiki](https://github.com/john30/ebusd/wiki) for installation (also available as Home Assistant add-on) - the **message definitions** from [john30/ebusd-configuration](https://github.com/john30/ebusd-configuration) as a **local copy with additions**: upstream reads only the first time slot of each day and hot water without - temperature. The card needs all three slots, see + temperature. The card needs all slots of each day, see [ebusd configuration](https://citoki.github.io/ebusd-time-program/ebusd-config/) - **MQTT** in ebusd with Home Assistant discovery (`mqtt-hassio.cfg`), see the [MQTT integration wiki](https://github.com/john30/ebusd/wiki/MQTT-integration) diff --git a/dev/scenarios.ts b/dev/scenarios.ts index 285efdc..06d5dbe 100644 --- a/dev/scenarios.ts +++ b/dev/scenarios.ts @@ -2,7 +2,7 @@ import { programEntityIds } from "../src/adapters/mqtt.js"; import { entityId, type ResolvedConfig } from "../src/config.js"; import type { HassEntity } from "../src/hass.js"; import { readMessage } from "../src/model/payload.js"; -import { MAX_SLOTS, PROGRAMS } from "../src/model/programs.js"; +import { PROGRAMS } from "../src/model/programs.js"; import type { Day, ProgramSpec } from "../src/model/types.js"; import type { FakeEbusd } from "../test/fake-ebusd.js"; import { sampleStates } from "../test/fixtures/hass-states.js"; @@ -37,7 +37,7 @@ function setAll(states: Record, cfg: ResolvedConfig, spec: P /** The slot sensors of some days (count stays known), like ebusd not having read them yet. */ function setDays(states: Record, cfg: ResolvedConfig, spec: ProgramSpec, days: Day[], state: string) { for (const day of days) { - for (let s = 0; s < MAX_SLOTS; s++) { + for (let s = 0; s < spec.maxSlots; s++) { const msg = readMessage(spec, day, s); for (const field of ["htm", "htm_1", "slottemp"]) { const id = entityId(cfg, msg, field); diff --git a/docs/ebusd-config.md b/docs/ebusd-config.md index 43e1083..2b4eef5 100644 --- a/docs/ebusd-config.md +++ b/docs/ebusd-config.md @@ -12,8 +12,9 @@ automatically. For the time programs they are not complete yet, so you need a ** - read only the **first slot** of each day (`Z1Timer_Monday0`, but no `…Monday1` and `…Monday2`), - read and write hot water slots **without a temperature**. - The controller has up to three slots per day, with a temperature for zones and hot water. The card needs all - of them, otherwise a program stays at **Waiting for values from eBUSd**. + The controller has up to 12 slots per day for zones and 3 for hot water and circulation, with a temperature + for zones and hot water. The card needs every slot a day uses, otherwise a program stays at + **Waiting for values from eBUSd**. ## 1. Use a local copy of the definitions @@ -73,11 +74,16 @@ Each program needs three kinds of messages in `15.ctlv2.csv`. `

` is the progr | Message | Direction | Fields the card uses | |---|---|---| | `

_Timeslots` (older configs: `_Timeframes`) | read, polled | `slotcount`, `slotcount_1` … `slotcount_6` (Monday … Sunday) | -| `

_0`, `

_1`, `

_2` | read, polled | `htm` (start), `htm_1` (end), `slottemp` (not for circulation) | +| `

_0`, `

_1`, `

_2` (zones up to `

_11`) | read, polled | `htm` (start), `htm_1` (end), `slottemp` (not for circulation) | | `

_` | write | `slotindex`, `slotcount`, `htm`, `htm_1`, `slottemp` (circulation: a constant instead) | So per program: one count message, 21 read messages (7 days × 3 slots) and 7 write messages. +Heating zones can have up to **12 slots** per day (hot water and circulation: 3). If you use more than 3 slots on a +zone, add the read messages `

_3` … `

_11` (slot bytes `03` … `0b`) as far as you need them; a day +with more slots than read messages stays at **Waiting for values from eBUSd**. The write message is the same for +any number of slots. + ### Example: zone 1, Monday These are the lines from the tested configuration. The other days only differ in the name and in one byte of the @@ -106,7 +112,7 @@ All timer messages use `b555`. The id encodes program, day and slot: | `ZZ` zone | `00` zone 1, `01` zone 2, `02` zone 3 (hot water and circulation: `00`) | | `TT` type | `00` heating, `02` hot water, `03` circulation | | `DD` day | `00` Monday … `06` Sunday | -| `SS` slot | `00`, `01`, `02` | +| `SS` slot | `00` … `02` (zones: up to `0b`) | For example hot water: `HwcTimer_Timeslots` = `a40002`, `HwcTimer_Monday0` = `a500020000`, `HwcTimer_Monday` = `a6000200`. Zone 2: `Z2Timer_Monday0` = `a501000000`. diff --git a/docs/ebusd.md b/docs/ebusd.md index 3756eae..83c8e48 100644 --- a/docs/ebusd.md +++ b/docs/ebusd.md @@ -20,13 +20,13 @@ You need: [Home Assistant add-on](https://github.com/LukasGrebe/ha-addons), with MQTT enabled - Home Assistant MQTT discovery in ebusd (`--mqttint=/etc/ebusd/mqtt-hassio.cfg`), see the [ebusd MQTT wiki](https://github.com/john30/ebusd/wiki/MQTT-integration) -- the controller's message definitions, e.g. `15.ctlv2.csv` for the VRC 720, with **all three slots per day** +- the controller's message definitions, e.g. `15.ctlv2.csv` for the VRC 720, with **all slots per day** of the `…Timer_` messages. The upstream definitions don't have them yet, see [ebusd configuration](ebusd-config.md) ## What the card reads -For each program and day the controller has up to three slots. ebusd exposes each slot as one message, and +For each program and day the controller has up to 12 slots (zones) or 3 slots (hot water, circulation). ebusd exposes each slot as one message, and discovery turns its fields into sensors. With the defaults (`mqtt_prefix: ebusd`, `circuit: ctlv2`): | Entity | Content | @@ -34,7 +34,7 @@ discovery turns its fields into sensors. With the defaults (`mqtt_prefix: ebusd` | `sensor.ebusd_ctlv2_z1timer_monday0_htm` | start of slot 0 on Monday, e.g. `06:00` | | `sensor.ebusd_ctlv2_z1timer_monday0_htm_1` | end of slot 0 | | `sensor.ebusd_ctlv2_z1timer_monday0_slottemp` | temperature of slot 0 (zones and hot water) | -| `sensor.ebusd_ctlv2_z1timer_monday1_…`, `…monday2_…` | slots 1 and 2 | +| `sensor.ebusd_ctlv2_z1timer_monday1_…` … `…monday11_…` | slots 1 … 11 (hot water and circulation: up to 2) | | `sensor.ebusd_ctlv2_z1timer_timeslots_slotcount` | number of slots on Monday | | `sensor.ebusd_ctlv2_z1timer_timeslots_slotcount_1` … `_6` | number of slots Tuesday … Sunday | | `sensor.ebusd_ctlv2_z1setbacktemp` | set-back temperature of zone 1, shown in the info text (optional; `number.…` when writes are discovered too; older configs: `…_z1nighttemp`) | diff --git a/docs/index.md b/docs/index.md index 2c49b09..85efb98 100644 --- a/docs/index.md +++ b/docs/index.md @@ -13,7 +13,8 @@ checks each day against what the controller reports back. - **Heating zones 1–3, hot water and circulation**, each on its own tab - **Edit several days at once**: quick selection for Mo–Fr, Sa–Su or all days; days with different programs are pointed out before you overwrite them -- **Up to 3 slots per day** in 10-minute steps, with a temperature per slot for zones and hot water +- **Up to 12 slots per day** for heating zones and 3 for hot water and circulation, in 10-minute steps, with a + temperature per slot for zones and hot water - **Checks before writing**: overlaps, end before start, temperatures out of range, touching slots that could be merged - **Verified writes**: every day is read back from the controller; if one doesn't match, retry, continue or restore - **Week preview** with a marker for the current time, and a read-only [preview mode](usage.md#preview-mode) diff --git a/docs/usage.md b/docs/usage.md index 77dd3e8..7b6724a 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -17,7 +17,9 @@ the program of one of them; pick which day to start from, or **Start empty**. Wh ## Edit time slots -Each day has up to **3 slots**. Times are set in 10-minute steps, `24:00` is allowed as an end time. Some controllers +Each day has up to **12 slots** for heating zones and up to **3 slots** for hot water and circulation. These are +the controller's limits: the VRC 720 documentation allows 12 slots for zones, even though the myVAILLANT app only +offers 3. Times are set in 10-minute steps, `24:00` is allowed as an end time. Some controllers (e.g. Saunier Duval BASS3) also accept single minutes, such as `17:22` written directly via eBUS: the card shows and keeps such times; changing one moves it to the next 10-minute step. diff --git a/src/adapters/mqtt.ts b/src/adapters/mqtt.ts index 4175ebe..11a14d1 100644 --- a/src/adapters/mqtt.ts +++ b/src/adapters/mqtt.ts @@ -2,7 +2,6 @@ import { COUNT_MESSAGE_CANDIDATES, entityId, type ResolvedConfig } from "../conf import type { Hass } from "../hass.js"; import { parseCount, parseDay, type RawSlot } from "../model/parse.js"; import { readMessage } from "../model/payload.js"; -import { MAX_SLOTS } from "../model/programs.js"; import { DAYS, type Day, type ProgramSpec, type Slot } from "../model/types.js"; /** @@ -46,7 +45,7 @@ export function programEntityIds(cfg: ResolvedConfig, spec: ProgramSpec, countMe const ids: string[] = []; DAYS.forEach((day, i) => { ids.push(entityId(cfg, `${spec.messagePrefix}_${countMessage}`, countField(i))); - for (let s = 0; s < MAX_SLOTS; s++) { + for (let s = 0; s < spec.maxSlots; s++) { const msg = readMessage(spec, day, s); ids.push(entityId(cfg, msg, FIELD.start), entityId(cfg, msg, FIELD.end)); if (spec.temp) ids.push(entityId(cfg, msg, FIELD.temp)); @@ -69,9 +68,9 @@ export function readProgram(hass: Hass, cfg: ResolvedConfig, spec: ProgramSpec): const state = (id: string) => hass.states[id]?.state; const days = { ...empty }; DAYS.forEach((day, i) => { - const count = parseCount(state(entityId(cfg, `${spec.messagePrefix}_${countMessage}`, countField(i)))); + const count = parseCount(state(entityId(cfg, `${spec.messagePrefix}_${countMessage}`, countField(i))), spec); const raw: RawSlot[] = []; - for (let s = 0; s < MAX_SLOTS; s++) { + for (let s = 0; s < spec.maxSlots; s++) { const msg = readMessage(spec, day, s); const slot: RawSlot = { start: state(entityId(cfg, msg, FIELD.start)), diff --git a/src/components/slot-list.ts b/src/components/slot-list.ts index 2f4e8ed..19b10a6 100644 --- a/src/components/slot-list.ts +++ b/src/components/slot-list.ts @@ -1,6 +1,5 @@ import { html, nothing, svg, type TemplateResult } from "lit"; import { formatTemp, issueMessage, UI } from "../i18n/index.js"; -import { MAX_SLOTS } from "../model/programs.js"; import type { ProgramSpec, Slot } from "../model/types.js"; import type { Issue } from "../model/validate.js"; import { tempBand } from "./colors.js"; @@ -170,7 +169,7 @@ function renderMerge(p: SlotListProps, i: number): TemplateResult { } function renderAdd(p: SlotListProps, count: number): TemplateResult { - const left = MAX_SLOTS - count; + const left = p.spec.maxSlots - count; return html`

${p.addBlocked ?? UI.slotsLeft(left)} diff --git a/src/ebusd-time-program-card.ts b/src/ebusd-time-program-card.ts index 218f48b..6450ad5 100644 --- a/src/ebusd-time-program-card.ts +++ b/src/ebusd-time-program-card.ts @@ -12,7 +12,6 @@ import { accentStyle, COUNT_MESSAGE_CANDIDATES, DEFAULTS, isServiceSource, resol import type { Hass } from "./hass.js"; import { formatTemp, programName, setLanguage, UI } from "./i18n/index.js"; import { clampTemp, defaultTemp, openTime, mergedSlot, mergeNeedsTemp, mergeSlots, removeSlot, sortSlots, suggestSlot, updateSlot } from "./model/edit.js"; -import { MAX_SLOTS } from "./model/programs.js"; import { fromMinutes, toMinutes } from "./model/time.js"; import { DAYS, type Day, type ProgramSpec, type Slot, type Week } from "./model/types.js"; import { validateDay, validateSelection, type Issue } from "./model/validate.js"; @@ -869,7 +868,7 @@ function sheetPatch(sheet: SheetState): Partial { } function addBlocked(slots: readonly Slot[], spec: ProgramSpec): string | null { - if (slots.length >= MAX_SLOTS) return UI.issues.too_many_slots({ max: MAX_SLOTS }); + if (slots.length >= spec.maxSlots) return UI.issues.too_many_slots({ max: spec.maxSlots }); return suggestSlot(slots, spec) ? null : UI.noGap; } diff --git a/src/model/edit.ts b/src/model/edit.ts index 2583c79..1ca954f 100644 --- a/src/model/edit.ts +++ b/src/model/edit.ts @@ -1,4 +1,4 @@ -import { MAX_SLOTS, TIME_STEP } from "./programs.js"; +import { TIME_STEP } from "./programs.js"; import { perSlotTemp } from "./week.js"; import { fromMinutes, isOnGrid, MINUTES_PER_DAY, roundToStep, toMinutes } from "./time.js"; import type { ProgramSpec, Slot, TempRange } from "./types.js"; @@ -133,10 +133,10 @@ const NEW_SLOT_GAP = 60; /** * Proposal for "Add time slot": one hour, one hour after the last slot; if * that doesn't fit, the first free gap of the day. The temperature is copied - * from the last slot. Returns null when the day is full (3 slots or no gap). + * from the last slot. Returns null when the day is full (`spec.maxSlots` or no gap). */ export function suggestSlot(slots: readonly Slot[], spec: ProgramSpec): Slot | null { - if (slots.length >= MAX_SLOTS) return null; + if (slots.length >= spec.maxSlots) return null; const ranges = sortSlots(slots) .map((s) => ({ start: toMinutes(s.start), end: toMinutes(s.end) })) .filter((r): r is { start: number; end: number } => r.start !== null && r.end !== null && r.end > r.start); diff --git a/src/model/parse.ts b/src/model/parse.ts index 73b341c..32a3129 100644 --- a/src/model/parse.ts +++ b/src/model/parse.ts @@ -1,4 +1,3 @@ -import { MAX_SLOTS } from "./programs.js"; import { toMinutes } from "./time.js"; import type { ProgramSpec, Slot } from "./types.js"; @@ -13,11 +12,11 @@ export interface RawSlot { temp?: string | undefined; } -/** Parse a slot-count sensor state (`"2"`) into 0..MAX_SLOTS, or null if unusable. */ -export function parseCount(state: string | undefined): number | null { +/** Parse a slot-count sensor state (`"2"`) into 0..spec.maxSlots, or null if unusable. */ +export function parseCount(state: string | undefined, spec: ProgramSpec): number | null { if (state === undefined) return null; const n = Number(state); - return Number.isInteger(n) && n >= 0 && n <= MAX_SLOTS ? n : null; + return Number.isInteger(n) && n >= 0 && n <= spec.maxSlots ? n : null; } /** diff --git a/src/model/programs.ts b/src/model/programs.ts index 90df1c7..9f8cf18 100644 --- a/src/model/programs.ts +++ b/src/model/programs.ts @@ -1,7 +1,13 @@ import type { ProgramId, ProgramSpec } from "./types.js"; -/** Vaillant limit: at most 3 slots per day. Fixed, not configurable. */ -export const MAX_SLOTS = 3; +/** + * Slots per day of the heating zones. The VRC 720 documentation allows up to 12 + * (the myVAILLANT app only offers 3); BASS3 confirms 12 on eBUS (issue #18). + */ +export const ZONE_MAX_SLOTS = 12; + +/** Slots per day of hot water and circulation: 3 (issue #18). */ +export const HWC_MAX_SLOTS = 3; /** Grid of the controller / myVAILLANT app in minutes. Fixed, not configurable. */ export const TIME_STEP = 10; @@ -14,6 +20,7 @@ const zone = (n: 1 | 2 | 3): ProgramSpec => ({ id: `z${n}`, messagePrefix: `Z${n}Timer`, temp: { min: 5, max: 30, step: 0.5 }, + maxSlots: ZONE_MAX_SLOTS, lowTempWarning: 15, defaultTemp: 20, setbackMessages: [`Z${n}SetbackTemp`, `Z${n}NightTemp`], @@ -27,6 +34,7 @@ export const PROGRAMS: Record = { id: "hwc", messagePrefix: "HwcTimer", temp: { min: 35, max: 70, step: 0.5 }, + maxSlots: HWC_MAX_SLOTS, defaultTemp: 50, sharedTempMessages: ["HwcTempDesired"], }, @@ -34,5 +42,6 @@ export const PROGRAMS: Record = { id: "cc", messagePrefix: "CcTimer", temp: null, + maxSlots: HWC_MAX_SLOTS, }, }; diff --git a/src/model/types.ts b/src/model/types.ts index 780428f..4b5579e 100644 --- a/src/model/types.ts +++ b/src/model/types.ts @@ -38,6 +38,8 @@ export interface ProgramSpec { messagePrefix: string; /** null = slots carry no temperature (CC). */ temp: TempRange | null; + /** Controller limit of slots per day: 12 for zones, 3 for HWC and CC. Fixed, not configurable. */ + maxSlots: number; /** Below this a warning is shown (does not block). */ lowTempWarning?: number; /** Temperature of a new slot when there is no previous slot to copy. */ diff --git a/src/model/validate.ts b/src/model/validate.ts index 660f040..d52c863 100644 --- a/src/model/validate.ts +++ b/src/model/validate.ts @@ -1,4 +1,3 @@ -import { MAX_SLOTS } from "./programs.js"; import { isOnStep, roundToStep, toMinutes } from "./time.js"; import type { Day, ProgramSpec, Slot } from "./types.js"; import { perSlotTemp } from "./week.js"; @@ -41,8 +40,8 @@ export const hasErrors = (issues: readonly Issue[]): boolean => export function validateDay(slots: readonly Slot[], spec: ProgramSpec): Issue[] { const issues: Issue[] = []; - if (slots.length > MAX_SLOTS) { - issues.push({ level: "error", code: "too_many_slots", params: { max: MAX_SLOTS } }); + if (slots.length > spec.maxSlots) { + issues.push({ level: "error", code: "too_many_slots", params: { max: spec.maxSlots } }); } const parsed: { idx: number; start: number; end: number; temp: number | undefined }[] = []; diff --git a/test/edit.test.ts b/test/edit.test.ts index d9a15d8..d4a0920 100644 --- a/test/edit.test.ts +++ b/test/edit.test.ts @@ -217,6 +217,9 @@ describe("suggestSlot", () => { { start: "05:00", end: "06:00" }, ]; expect(suggestSlot(three, cc)).toBeNull(); + expect(suggestSlot(three.map((s) => ({ ...s, temp: 20 })), z1)).not.toBeNull(); + const twelve: Slot[] = Array.from({ length: 12 }, (_, i) => ({ start: `${String(i + 1).padStart(2, "0")}:00`, end: `${String(i + 1).padStart(2, "0")}:30`, temp: 20 })); + expect(suggestSlot(twelve, z1)).toBeNull(); expect(suggestSlot([{ start: "00:00", end: "24:00" }], cc)).toBeNull(); }); diff --git a/test/fake-ebusd.ts b/test/fake-ebusd.ts index bad3579..bdc3908 100644 --- a/test/fake-ebusd.ts +++ b/test/fake-ebusd.ts @@ -2,7 +2,7 @@ import { countField, detectCountMessage, FIELD, readProgram } from "../src/adapt import { entityId, type ResolvedConfig } from "../src/config.js"; import type { Hass, HassEntity } from "../src/hass.js"; import { readMessage, writeMessage } from "../src/model/payload.js"; -import { MAX_SLOTS, PROGRAMS } from "../src/model/programs.js"; +import { PROGRAMS } from "../src/model/programs.js"; import { DAYS, type Day, type ProgramSpec, type Slot } from "../src/model/types.js"; /** @@ -225,7 +225,7 @@ export class FakeEbusd { /** Message names ebusd reads for a program: the count message, then each day's slots. */ readMessages(spec: ProgramSpec): string[] { const count = `${spec.messagePrefix}_${detectCountMessage(this.hass(), this.cfg, spec) ?? "Timeframes"}`; - return [count, ...DAYS.flatMap((day) => Array.from({ length: MAX_SLOTS }, (_, s) => readMessage(spec, day, s)))]; + return [count, ...DAYS.flatMap((day) => Array.from({ length: spec.maxSlots }, (_, s) => readMessage(spec, day, s)))]; } private onGet(message: string): void { @@ -241,7 +241,7 @@ export class FakeEbusd { }); } for (const day of DAYS) { - for (let s = 0; s < MAX_SLOTS; s++) { + for (let s = 0; s < spec.maxSlots; s++) { const msg = readMessage(spec, day, s); if (msg !== message) continue; const slot = this.controllerDay(spec, day)[s]; diff --git a/test/fixtures/hass-states.ts b/test/fixtures/hass-states.ts index 807e36a..9c3cd4d 100644 --- a/test/fixtures/hass-states.ts +++ b/test/fixtures/hass-states.ts @@ -2,7 +2,7 @@ import { countField, FIELD } from "../../src/adapters/mqtt.js"; import { entityId, resolveConfig } from "../../src/config.js"; import type { HassEntity } from "../../src/hass.js"; import { readMessage } from "../../src/model/payload.js"; -import { MAX_SLOTS, PROGRAMS } from "../../src/model/programs.js"; +import { PROGRAMS } from "../../src/model/programs.js"; import { DAYS, type ProgramId, type Slot, type Week } from "../../src/model/types.js"; /** @@ -61,7 +61,7 @@ export function sampleStates(weeks: Partial> = SAMPLE_WE DAYS.forEach((day, i) => { set(entityId(cfg, `${spec.messagePrefix}_Timeframes`, countField(i)), String(days[day].length)); // ebusd reads unused slots as 00:00–00:00 without a temperature - for (let s = 0; s < MAX_SLOTS; s++) { + for (let s = 0; s < spec.maxSlots; s++) { const slot = days[day][s]; const msg = readMessage(spec, day, s); set(entityId(cfg, msg, FIELD.start), slot?.start ?? "00:00"); diff --git a/test/payload-parse.test.ts b/test/payload-parse.test.ts index 5951211..0928967 100644 --- a/test/payload-parse.test.ts +++ b/test/payload-parse.test.ts @@ -97,10 +97,16 @@ describe("parseCount", () => { ["2", 2], ["0", 0], ["3", 3], - ])("%s", (s, n) => expect(parseCount(s)).toBe(n)); + ])("%s", (s, n) => expect(parseCount(s, cc)).toBe(n)); it.each([undefined, "unknown", "unavailable", "4", "-1", "1.5"])("rejects %j", (s) => - expect(parseCount(s)).toBeNull(), + expect(parseCount(s, cc)).toBeNull(), ); + it("zones accept up to 12 slots (issue #18)", () => { + expect(parseCount("5", z1)).toBe(5); + expect(parseCount("12", z1)).toBe(12); + expect(parseCount("13", z1)).toBeNull(); + expect(parseCount("4", hwc)).toBeNull(); + }); }); describe("parseDay – HA sensor states as read on 2026-11-04", () => { diff --git a/test/validate.test.ts b/test/validate.test.ts index 72e0c71..adbdc38 100644 --- a/test/validate.test.ts +++ b/test/validate.test.ts @@ -56,10 +56,23 @@ describe("validateDay – errors", () => { expect(issues[0]).toMatchObject({ code: "overlap", slot: 0, params: { other: 2 } }); expect(issueMessage(issues[0]!)).toBe("Overlaps with slot 2 (06:30–11:30)"); }); - it("more than 3 slots", () => { + it("more than 3 slots for CC", () => { const slots = ["01", "03", "05", "07"].map((h) => ({ start: `${h}:00`, end: `${h}:30` })); expect(codes(validateDay(slots, cc))).toEqual(["too_many_slots"]); }); + it("more than 3 slots for HWC", () => { + const slots = ["01", "03", "05", "07"].map((h) => ({ start: `${h}:00`, end: `${h}:30`, temp: 50 })); + expect(validateDay(slots, hwc).filter((i) => i.code === "too_many_slots")).toEqual([ + { level: "error", code: "too_many_slots", params: { max: 3 } }, + ]); + }); + it("up to 12 slots for zones, not more (issue #18)", () => { + const hours = Array.from({ length: 13 }, (_, i) => String(i + 1).padStart(2, "0")); + const slots = hours.map((h) => ({ start: `${h}:00`, end: `${h}:30`, temp: 20 })); + expect(codes(validateDay(slots.slice(0, 12), z1))).toEqual([]); + expect(codes(validateDay(slots, z1))).toEqual(["too_many_slots"]); + expect(validateDay(slots, z1)[0]).toMatchObject({ params: { max: 12 } }); + }); it("missing temperature for Z1", () => { expect(codes(validateDay([{ start: "06:00", end: "07:00" }], z1))).toEqual(["temp_missing"]); });