registry: SceneController events, DoorbellEventSource, SimpleEventSource, TimeHoldController, InventoryLevelSensor, WakeOnLANController

Six descriptors written from their pages replace the last stubs of tiers 1 and 2. A scene answers Activate and
Deactivate through ctx.respond() with ActivationStarted and DeactivationStarted, the time and the cause filled
in. device.raise(descriptor, name, payload) publishes DoorbellPress and the Event of a button on <root>/event
with the endpoint and a new messageId; it throws a MessageError for an interface or instance the device did
not declare, an event that answers a directive, a payload that does not fit and a message over 16000 bytes.
TurnOn of a device with WakeOnLANController is deferred without the warning.

On the wire: a doorbell has no properties object and proactivelyReported on the capability; SimpleEventSource
is version 1.0, InventoryLevelSensor and WakeOnLANController version 3 (1.5.2: 1). A scene declared without
options is announced as before. Alex2MQTT has no topic yet for the WakeUp event.
24 examples of the six pages are saved as fixtures. 267 tests pass, 241 before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
David 2026-09-28 21:01:53 +00:00
parent d7dfc5b122
commit 3a07c861b1
116 changed files with 3136 additions and 166 deletions

View file

@ -0,0 +1,51 @@
import { at, mismatch, s } from "../schema.js";
import { defineInterface } from "../types.js";
// As the examples of the page spell them; its table has them in lower case
const KINDS = ["Count", "Percentage", "Volume", "Weight"];
// A volume and a weight have a unit: MILLILITER, GRAM (alexa-property-schemas.html, "Volume unit values" and
// "Weight unit values")
function withUnit(fields) {
return {
expects: fields.expects,
parse(input, path = "") {
const measured = fields.parse(input, path);
const what = measured["@type"].toLowerCase();
const needed = what === "volume" || what === "weight";
if (needed && measured.unit === undefined)
throw mismatch(at(path, "unit"), `the unit of the ${what}, like MILLILITER or GRAM`, undefined);
if (!needed && measured.unit !== undefined)
throw mismatch(at(path, "unit"), `no unit for a ${what}`, measured.unit);
return measured;
},
};
}
const kind = s.enum(...KINDS);
const measurement = withUnit(s.object({ "@type": kind, unit: s.optional(s.string({ min: 1 })) }, { unknownKeys: "reject" }));
const level = withUnit(s.object({ "@type": kind, value: s.number({ min: 0 }), unit: s.optional(s.string({ min: 1 })) }));
/**
* How much is left of something a device uses up: ink, paper, detergent. Each instance is one sensor, and Amazon
* orders a refill by its Dash replenishment id. The level is reported, there is nothing to ask for by voice.
*/
export const InventoryLevelSensor = defineInterface({
namespace: "Alexa.InventoryLevelSensor",
version: "3",
doc: "https://developer.amazon.com/docs/alexaplus/device-apis/alexa-inventorylevelsensor.html",
kind: "sensor",
tier: 2,
instanced: true,
properties: {
level: { name: "level", value: level, note: "measured as the capability declares it" },
},
directives: {},
options: s.object({
/** How the level is measured: { "@type": "Volume", unit: "MILLILITER" }, { "@type": "Count" }. */
measurement,
/** The id the Dash console gave for the product. */
replenishment: s.object({ "@type": s.enum("DashReplenishmentId"), value: s.string({ min: 1 }) }, { unknownKeys: "reject" }),
}, { unknownKeys: "reject" }),
// A capability declared the 1.x way has neither; check() says so
discovery({ options: { measurement: measured, replenishment } }) {
const configuration = { ...(measured && { measurement: measured }), ...(replenishment && { replenishment }) };
return Object.keys(configuration).length > 0 ? { configuration } : {};
},
});