registry: ThermostatController 3.2 and ThermostatController.Schedule

The thermostat is described from its page: one, two or three setpoints with holdUntil, AdjustTargetTemperature,
SetThermostatMode with the six modes (EM_HEAT is new), ResumeSchedule, adaptiveRecoveryStatus, and its seven error
types under Alexa.ThermostatController. A declaration gives supportedModes, supportsScheduling and the properties
the device has; without them discovery is what 1.5.2 sent: HEAT, COOL, AUTO, OFF and the three setpoints with
thermostatMode. supportedModes without HEAT or COOL is refused where it is declared.

ThermostatController.Schedule replaces its stub. Wire change for a 1.x declaration of it: version 3.2 (was 1) and
scheduleEnabled listed (was nothing). SetAdaptiveRecovery is taken only with supportsAdaptiveRecovery.

24 examples of three pages are saved as fixtures; the page folds the SetWeeklySchedule example away, its payload
is tested from the tables. 207 tests pass, 191 before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
David 2026-09-28 20:34:49 +00:00
parent af1489696d
commit f555a5df70
67 changed files with 2445 additions and 58 deletions

View file

@ -3,7 +3,10 @@
// the page prints it, and a payload that does not fit is answered with INVALID_VALUE without the handler.
const { test } = require("node:test");
const assert = require("node:assert/strict");
const { Alex2MQTT, LockController, MemoryPublisher, PowerLevelController, registry } = require("alex2node");
const {
Alex2MQTT, AlexaErrors, LockController, MemoryPublisher, PowerLevelController, ThermostatController,
ThermostatControllerSchedule, registry,
} = require("alex2node");
const interfaces = require("../fixtures/interfaces.js");
const { doc, examples } = require("../helpers/fixtures.js");
const { directive } = require("../helpers/harness.js");
@ -80,3 +83,37 @@ test("Alexa.LockController: a slow lock defers without a warning, and answers as
"warning: Amazon documents no DeferredResponse for Alexa.PowerLevelController, Alexa may not wait for the answer",
]);
});
test("Alexa.ThermostatController: an error of the thermostat goes under its namespace, a temperature out of range under Alexa", async () => {
const { device, receive, answers } = bridgeWithout();
const celsius = (value) => ({ value, scale: "CELSIUS" });
const thrown = [
AlexaErrors.setpointsTooClose("The setpoints are too close.", celsius(2)),
AlexaErrors.of("THERMOSTAT_IS_OFF", "The thermostat is currently off."),
AlexaErrors.temperatureOutOfRange("The requested temperature of -15 is out of range.", { minimumValue: celsius(15), maximumValue: celsius(30) }),
];
let count = 0;
device.add(ThermostatController).on("SetTargetTemperature", () => { throw thrown[count++]; });
device.add(ThermostatControllerSchedule, { supportedFanModes: ["AUTO"], supportsAdaptiveRecovery: false })
.on("SetWeeklySchedule", (ctx) => ctx.error("INSUFFICIENT_SPACE", "the thermostat keeps four entries a day"));
const set = doc("alexa-thermostatcontroller", "SetTargetTemperature-single.directive").directive;
for (let i = 0; i < thrown.length; i += 1) await receive(set);
const printed = ["REQUESTED_SETPOINTS_TOO_CLOSE", "THERMOSTAT_IS_OFF", "TEMPERATURE_VALUE_OUT_OF_RANGE"]
.map((type) => doc("alexa-thermostatcontroller-errorresponse", `${type}.error`).event);
assert.deepEqual(answers(), printed.map(({ header, payload }) => ["alexaResponce", header.namespace, "ErrorResponse", payload]));
assert.deepEqual(printed.map(({ header }) => header.namespace), ["Alexa.ThermostatController", "Alexa.ThermostatController", "Alexa"]);
await receive(directive("Alexa.ThermostatController.Schedule", "SetWeeklySchedule", "device-1", "ct", {}));
assert.deepEqual(answers().at(-1), [
"alexaResponce", "Alexa.ThermostatController.Schedule", "ErrorResponse",
{ type: "INSUFFICIENT_SPACE", message: "the thermostat keeps four entries a day" },
]);
// Declared without adaptive recovery, the thermostat is not sent the directive that switches it
await receive(doc("alexa-thermostatcontroller-schedule", "SetAdaptiveRecovery.directive").directive);
assert.deepEqual(answers().at(-1), ["alexaResponce", "Alexa", "ErrorResponse", {
type: "INVALID_DIRECTIVE",
message: "Alexa.ThermostatController.Schedule as device-1 declares it does not take SetAdaptiveRecovery",
}]);
});