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:
parent
af1489696d
commit
f555a5df70
67 changed files with 2445 additions and 58 deletions
|
|
@ -76,9 +76,9 @@ export class AlexaInterface extends Capability<any, any, Options> {
|
|||
return this.descriptor.version;
|
||||
}
|
||||
|
||||
/** @deprecated Read the keys of descriptor.properties. */
|
||||
/** @deprecated The properties discovery lists: read properties.supported of toJSON(). */
|
||||
getProps(): string[] {
|
||||
return Object.keys(this.descriptor.properties);
|
||||
return (super.toJSON().properties?.supported ?? []).map(({ name }) => name);
|
||||
}
|
||||
|
||||
getJSON(): CapabilityJson {
|
||||
|
|
|
|||
|
|
@ -177,6 +177,8 @@ export enum ThermostatMode {
|
|||
AUTO = "AUTO",
|
||||
ECO = "ECO",
|
||||
CUSTOM = "CUSTOM",
|
||||
/** Emergency heating, since 2.0. */
|
||||
EM_HEAT = "EM_HEAT",
|
||||
}
|
||||
|
||||
/** The scale of a temperature given to addTemperatureSensorProp() and addThermostatControllerProp(). */
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ export class Capability<P extends Properties = Properties, D extends Directives
|
|||
};
|
||||
if (extras.properties !== false) {
|
||||
json.properties = {
|
||||
supported: Object.keys(descriptor.properties).map((name) => ({ name })),
|
||||
supported: (extras.supported ?? Object.keys(descriptor.properties)).map((name) => ({ name })),
|
||||
proactivelyReported: this.proactivelyReported,
|
||||
retrievable: this.retrievable,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export { registry, DeclarationError, SchemaError } from "./registry/index.js";
|
|||
export {
|
||||
Alexa, BrightnessController, ColorController, ColorTemperatureController, ContactSensor, HumiditySensor, LockController,
|
||||
ModeController, MotionSensor, PercentageController, PowerLevelController, RangeController, TemperatureSensor,
|
||||
ToggleController,
|
||||
ThermostatController, ThermostatControllerSchedule, ToggleController,
|
||||
} from "./registry/index.js";
|
||||
export { PowerController, EndpointHealth } from "./compat/enums.js";
|
||||
export { asset, text, semantics, SemanticsBuilder } from "./registry/index.js";
|
||||
|
|
@ -19,13 +19,13 @@ export { asset, text, semantics, SemanticsBuilder } from "./registry/index.js";
|
|||
// The vocabularies of the Smart Home API
|
||||
export {
|
||||
ASSETS as Assets, UNITS_OF_MEASURE as Units, ACTIONS as Actions, STATES as States,
|
||||
DISPLAY_CATEGORIES as DisplayCategories,
|
||||
DISPLAY_CATEGORIES as DisplayCategories, THERMOSTAT_MODES as ThermostatModes,
|
||||
} from "./registry/index.js";
|
||||
export type {
|
||||
ActionId, AssetId, DisplayCategoryName, StateId, UnitOfMeasure,
|
||||
ActionsToDirective, AnyDescriptor, CapabilityExtras, Declared, DirectiveDescriptor, EndpointView, EventDescriptor,
|
||||
InterfaceDescriptor, Label, PropertyDescriptor, Semantics, StatesToRange, StatesToValue,
|
||||
ActionName, StateName, Mode, Infer, Schema, Temperature, TimeInterval,
|
||||
ActionName, StateName, Mode, ThermostatModeName, Infer, Schema, Temperature, TimeInterval,
|
||||
} from "./registry/index.js";
|
||||
|
||||
// The messages: what the bridge publishes, built from plain values
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import { PowerController } from "./interfaces/PowerController.js";
|
|||
import { PowerLevelController } from "./interfaces/PowerLevelController.js";
|
||||
import { RangeController } from "./interfaces/RangeController.js";
|
||||
import { TemperatureSensor } from "./interfaces/TemperatureSensor.js";
|
||||
import { ThermostatController } from "./interfaces/ThermostatController.js";
|
||||
import { ThermostatControllerSchedule } from "./interfaces/ThermostatControllerSchedule.js";
|
||||
import { ToggleController } from "./interfaces/ToggleController.js";
|
||||
import { STUBS } from "./interfaces/stubs.js";
|
||||
import { DeclarationError } from "./types.js";
|
||||
|
|
@ -35,6 +37,8 @@ const described: readonly AnyDescriptor[] = [
|
|||
PowerLevelController,
|
||||
RangeController,
|
||||
TemperatureSensor,
|
||||
ThermostatController,
|
||||
ThermostatControllerSchedule,
|
||||
ToggleController,
|
||||
];
|
||||
|
||||
|
|
@ -67,9 +71,11 @@ export const registry = {
|
|||
export {
|
||||
Alexa, BrightnessController, ColorController, ColorTemperatureController, ContactSensor, EndpointHealth, HumiditySensor,
|
||||
LockController, ModeController, MotionSensor, PercentageController, PowerController, PowerLevelController, RangeController,
|
||||
TemperatureSensor, ToggleController,
|
||||
TemperatureSensor, ThermostatController, ThermostatControllerSchedule, ToggleController,
|
||||
};
|
||||
export type { Mode } from "./interfaces/ModeController.js";
|
||||
export { THERMOSTAT_MODES } from "./interfaces/ThermostatController.js";
|
||||
export type { ThermostatModeName } from "./interfaces/ThermostatController.js";
|
||||
export { asset, text } from "./resources.js";
|
||||
export { semantics, SemanticsBuilder } from "./semantics.js";
|
||||
export type { ActionName, StateName } from "./semantics.js";
|
||||
|
|
|
|||
101
src/registry/interfaces/ThermostatController.ts
Normal file
101
src/registry/interfaces/ThermostatController.ts
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
import { mismatch, s } from "../schema.js";
|
||||
import type { Infer, Schema } from "../schema.js";
|
||||
import { DeclarationError, defineInterface } from "../types.js";
|
||||
|
||||
/** alexa-property-schemas.html, "ThermostatMode values". EM_HEAT, emergency heating, came with version 3.2. */
|
||||
export const THERMOSTAT_MODES = ["AUTO", "COOL", "ECO", "EM_HEAT", "HEAT", "OFF"] as const;
|
||||
export type ThermostatModeName = (typeof THERMOSTAT_MODES)[number];
|
||||
|
||||
const PROPERTIES = ["targetSetpoint", "lowerSetpoint", "upperSetpoint", "thermostatMode", "adaptiveRecoveryStatus"] as const;
|
||||
type PropertyName = (typeof PROPERTIES)[number];
|
||||
|
||||
// What 1.x announced for every thermostat. A declaration that leaves an option out announces the same.
|
||||
const MODES_OF_1X: readonly ThermostatModeName[] = ["HEAT", "COOL", "AUTO", "OFF"];
|
||||
const PROPERTIES_OF_1X: readonly PropertyName[] = ["targetSetpoint", "lowerSetpoint", "upperSetpoint", "thermostatMode"];
|
||||
|
||||
const setpoints = s.object({
|
||||
targetSetpoint: s.optional(s.temperature()),
|
||||
lowerSetpoint: s.optional(s.temperature()),
|
||||
upperSetpoint: s.optional(s.temperature()),
|
||||
holdUntil: s.optional(s.timeInterval()),
|
||||
});
|
||||
|
||||
// One setpoint for a thermostat that holds a temperature, the lower and the upper for one that holds a range, all
|
||||
// three for one that aims at a temperature within a range. The page marks each as not required; a payload without
|
||||
// any sets nothing.
|
||||
const setTargetTemperature: Schema<Infer<typeof setpoints>> = {
|
||||
expects: "one or more of targetSetpoint, lowerSetpoint, upperSetpoint",
|
||||
parse(input, path = "") {
|
||||
const payload = setpoints.parse(input, path);
|
||||
if (!payload.targetSetpoint && !payload.lowerSetpoint && !payload.upperSetpoint) throw mismatch(path, this.expects, input);
|
||||
return payload;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Version 3.2. A thermostat declares the properties it has: targetSetpoint for a single setpoint, lowerSetpoint and
|
||||
* upperSetpoint for two, all three for a target within a range. Temperatures are reported "in the same temperature
|
||||
* scale (Celsius or Fahrenheit) that the thermostat is set to display". An error of errorTypes goes under the
|
||||
* namespace of the interface, TEMPERATURE_VALUE_OUT_OF_RANGE under Alexa
|
||||
* (alexa-thermostatcontroller-errorresponse.html).
|
||||
*/
|
||||
export const ThermostatController = defineInterface({
|
||||
namespace: "Alexa.ThermostatController",
|
||||
version: "3.2",
|
||||
doc: "https://developer.amazon.com/docs/alexaplus/device-apis/alexa-thermostatcontroller.html",
|
||||
kind: "controller",
|
||||
tier: 1,
|
||||
instanced: false,
|
||||
properties: {
|
||||
targetSetpoint: { name: "targetSetpoint", value: s.temperature() },
|
||||
lowerSetpoint: { name: "lowerSetpoint", value: s.temperature() },
|
||||
upperSetpoint: { name: "upperSetpoint", value: s.temperature() },
|
||||
thermostatMode: { name: "thermostatMode", value: s.enum(...THERMOSTAT_MODES) },
|
||||
adaptiveRecoveryStatus: {
|
||||
name: "adaptiveRecoveryStatus",
|
||||
value: s.enum("PREHEATING", "PRECOOLING", "INACTIVE"),
|
||||
note: "heating or cooling ahead of an entry of the schedule, of Alexa.ThermostatController.Schedule",
|
||||
},
|
||||
},
|
||||
directives: {
|
||||
SetTargetTemperature: {
|
||||
name: "SetTargetTemperature",
|
||||
payload: setTargetTemperature,
|
||||
note: "holdUntil comes only to a thermostat declared with supportsScheduling",
|
||||
},
|
||||
AdjustTargetTemperature: { name: "AdjustTargetTemperature", payload: s.object({ targetSetpointDelta: s.temperature() }) },
|
||||
SetThermostatMode: {
|
||||
name: "SetThermostatMode",
|
||||
payload: s.object({ thermostatMode: s.object({ value: s.enum(...THERMOSTAT_MODES) }) }),
|
||||
},
|
||||
ResumeSchedule: { name: "ResumeSchedule", payload: s.object({}), note: "en-US only" },
|
||||
},
|
||||
options: s.object({
|
||||
/** Default: HEAT, COOL, AUTO, OFF. */
|
||||
supportedModes: s.optional(s.array(s.enum(...THERMOSTAT_MODES), { min: 1 })),
|
||||
/** The user can set a temperature for a time: SetTargetTemperature comes with holdUntil. Default: false. */
|
||||
supportsScheduling: s.optional(s.boolean()),
|
||||
/** The properties the thermostat has. Default: the three setpoints and thermostatMode. */
|
||||
properties: s.optional(s.array(s.enum(...PROPERTIES), { min: 1 })),
|
||||
}, { unknownKeys: "reject" }),
|
||||
discovery({ options: { supportedModes = MODES_OF_1X, supportsScheduling = false, properties = PROPERTIES_OF_1X } }) {
|
||||
return { supported: properties, configuration: { supportedModes, supportsScheduling } };
|
||||
},
|
||||
validate(capability) {
|
||||
const { supportedModes = MODES_OF_1X, properties = PROPERTIES_OF_1X } = capability.options;
|
||||
// alexa-thermostatcontroller.html, "Configuration object": "You must include at least one of HEAT or COOL"
|
||||
if (!supportedModes.includes("HEAT") && !supportedModes.includes("COOL")) {
|
||||
throw new DeclarationError(capability, `supportedModes ${supportedModes.join(", ")} has neither HEAT nor COOL, Alexa wants one`);
|
||||
}
|
||||
const lists: ReadonlyArray<readonly string[]> = [supportedModes, properties];
|
||||
for (const list of lists) {
|
||||
const twice = list.find((entry, i) => list.indexOf(entry) !== i);
|
||||
if (twice) throw new DeclarationError(capability, `${twice} is listed twice`);
|
||||
}
|
||||
},
|
||||
errorNamespace: "Alexa.ThermostatController",
|
||||
errorTypes: [
|
||||
"DUAL_SETPOINTS_UNSUPPORTED", "REQUESTED_SETPOINTS_TOO_CLOSE", "THERMOSTAT_IS_OFF", "TRIPLE_SETPOINTS_UNSUPPORTED",
|
||||
"UNSUPPORTED_THERMOSTAT_MODE", "UNWILLING_TO_SET_SCHEDULE", "UNWILLING_TO_SET_VALUE",
|
||||
],
|
||||
});
|
||||
81
src/registry/interfaces/ThermostatControllerSchedule.ts
Normal file
81
src/registry/interfaces/ThermostatControllerSchedule.ts
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
import { s } from "../schema.js";
|
||||
import { defineInterface } from "../types.js";
|
||||
|
||||
const FAN_MODES = ["ON", "AUTO", "CIRCULATE"] as const;
|
||||
|
||||
// alexa-thermostatcontroller-schedule.html, "ScheduleEntry object": an entry ends where the next one starts
|
||||
const entry = s.object({
|
||||
startTimeInMinutes: s.number({ min: 0, max: 1439, integer: true }),
|
||||
setpoints: s.object({ upperSetpoint: s.optional(s.temperature()), lowerSetpoint: s.optional(s.temperature()) }),
|
||||
/** Without a mode the fan runs as the manufacturer set it. */
|
||||
fanSetting: s.optional(s.object({ mode: s.optional(s.enum(...FAN_MODES)) })),
|
||||
activityType: s.optional(s.object({ type: s.enum("AWAY", "HOME", "SLEEP") })),
|
||||
});
|
||||
const day = s.array(entry);
|
||||
|
||||
// Same page, "WeeklySchedule object"
|
||||
const weeklySchedule = s.object({
|
||||
temperatureScale: s.enum("CELSIUS", "FAHRENHEIT", "KELVIN"),
|
||||
Monday: day,
|
||||
Tuesday: day,
|
||||
Wednesday: day,
|
||||
Thursday: day,
|
||||
Friday: day,
|
||||
Saturday: day,
|
||||
Sunday: day,
|
||||
});
|
||||
|
||||
/**
|
||||
* Version 3.2. The schedule a user writes in the Alexa app: the interface has no utterances. Discovery lists
|
||||
* adaptiveRecoveryEnabled for a thermostat declared with supportsAdaptiveRecovery, and Alexa sends
|
||||
* SetAdaptiveRecovery to such a thermostat only.
|
||||
*/
|
||||
export const ThermostatControllerSchedule = defineInterface({
|
||||
namespace: "Alexa.ThermostatController.Schedule",
|
||||
version: "3.2",
|
||||
doc: "https://developer.amazon.com/docs/alexaplus/device-apis/alexa-thermostatcontroller-schedule.html",
|
||||
kind: "controller",
|
||||
tier: 2,
|
||||
instanced: false,
|
||||
properties: {
|
||||
adaptiveRecoveryEnabled: { name: "adaptiveRecoveryEnabled", value: s.boolean() },
|
||||
scheduleEnabled: { name: "scheduleEnabled", value: s.boolean() },
|
||||
},
|
||||
directives: {
|
||||
SetWeeklySchedule: {
|
||||
name: "SetWeeklySchedule",
|
||||
payload: s.object({ weeklySchedule: s.optional(weeklySchedule) }),
|
||||
note: "a schedule the thermostat cannot keep leaves the one it has and is answered with an error",
|
||||
},
|
||||
SetScheduleState: {
|
||||
name: "SetScheduleState",
|
||||
payload: s.object({ scheduleEnabled: s.boolean() }),
|
||||
note: "a disabled schedule is kept: the user can enable it again",
|
||||
},
|
||||
SetAdaptiveRecovery: {
|
||||
name: "SetAdaptiveRecovery",
|
||||
payload: s.object({ adaptiveRecoveryEnabled: s.boolean() }),
|
||||
when: ({ options }) => options.supportsAdaptiveRecovery === true,
|
||||
},
|
||||
},
|
||||
options: s.object({
|
||||
supportedFanModes: s.array(s.enum(...FAN_MODES)),
|
||||
/** The thermostat heats or cools ahead of an entry, to be at its temperature when it starts. */
|
||||
supportsAdaptiveRecovery: s.boolean(),
|
||||
maxEntryPerDay: s.optional(s.number({ min: 1, integer: true })),
|
||||
}, { unknownKeys: "reject" }),
|
||||
// A capability declared the 1.x way has none of the options; check() says so, discovery lists what there is
|
||||
discovery({ options: { supportedFanModes, supportsAdaptiveRecovery, maxEntryPerDay } }) {
|
||||
const configuration = {
|
||||
...(supportedFanModes && { supportedFanModes }),
|
||||
...(supportsAdaptiveRecovery !== undefined && { supportsAdaptiveRecovery }),
|
||||
...(maxEntryPerDay !== undefined && { maxEntryPerDay }),
|
||||
};
|
||||
return {
|
||||
supported: supportsAdaptiveRecovery ? ["adaptiveRecoveryEnabled", "scheduleEnabled"] : ["scheduleEnabled"],
|
||||
...(Object.keys(configuration).length > 0 && { configuration }),
|
||||
};
|
||||
},
|
||||
errorNamespace: "Alexa.ThermostatController.Schedule",
|
||||
errorTypes: ["INSUFFICIENT_SPACE"],
|
||||
});
|
||||
|
|
@ -62,10 +62,8 @@ const TABLE: readonly Row[] = [
|
|||
["Alexa.SmartVision.SnapshotProvider", "1", [], "alexa-smartvision-snapshotprovider.html"],
|
||||
["Alexa.Speaker", "1", [], "alexa-speaker.html"],
|
||||
["Alexa.StepSpeaker", "1", [], "alexa-stepspeaker.html"],
|
||||
["Alexa.ThermostatController", "3.2", ["targetSetpoint", "lowerSetpoint", "upperSetpoint", "thermostatMode"], "alexa-thermostatcontroller.html"],
|
||||
["Alexa.ThermostatController.Configuration", "1", [], "alexa-thermostatcontroller-configuration.html"],
|
||||
["Alexa.ThermostatController.HVAC.Components", "1", [], "alexa-thermostatcontroller-hvac-components.html"],
|
||||
["Alexa.ThermostatController.Schedule", "1", [], "alexa-thermostatcontroller-schedule.html"],
|
||||
// "UNKNOWN" in 1.5.2 as well; the page is titled "Interface 3"
|
||||
["Alexa.TimeHoldController", "3", [], "alexa-timeholdcontroller.html"],
|
||||
["Alexa.UIController", "1", [], "alexa-uicontroller.html"],
|
||||
|
|
@ -74,16 +72,13 @@ const TABLE: readonly Row[] = [
|
|||
["Alexa.WakeOnLANController", "1", [], "alexa-wakeonlancontroller.html"],
|
||||
];
|
||||
|
||||
// What 1.5.2 added to the capability object of two of them
|
||||
// What 1.5.2 added to the capability object of one of them
|
||||
const EXTRAS: Record<string, AnyDescriptor["discovery"]> = {
|
||||
// No properties object; supportsDeactivation and proactivelyReported on the capability itself
|
||||
"Alexa.SceneController": ({ proactivelyReported }) => ({
|
||||
properties: false,
|
||||
topLevel: { supportsDeactivation: true, proactivelyReported },
|
||||
}),
|
||||
"Alexa.ThermostatController": () => ({
|
||||
configuration: { supportedModes: ["HEAT", "COOL", "AUTO", "OFF"], supportsScheduling: false },
|
||||
}),
|
||||
};
|
||||
|
||||
function kindOf(namespace: string): AnyDescriptor["kind"] {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,8 @@ export interface CapabilityExtras {
|
|||
topLevel?: Record<string, unknown>;
|
||||
/** false: the capability has no properties object (the Alexa interface, a scene). */
|
||||
properties?: false;
|
||||
/** The properties the capability lists, where a declaration has some of those of the interface. Default: all. */
|
||||
supported?: readonly string[];
|
||||
}
|
||||
|
||||
/** A capability as declared on an endpoint: what discovery() and validate() of its descriptor are given. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue