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>
54 lines
2.9 KiB
JavaScript
54 lines
2.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.InventoryLevelSensor = void 0;
|
|
const schema_js_1 = require("../schema.js");
|
|
const types_js_1 = require("../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 (0, schema_js_1.mismatch)((0, schema_js_1.at)(path, "unit"), `the unit of the ${what}, like MILLILITER or GRAM`, undefined);
|
|
if (!needed && measured.unit !== undefined)
|
|
throw (0, schema_js_1.mismatch)((0, schema_js_1.at)(path, "unit"), `no unit for a ${what}`, measured.unit);
|
|
return measured;
|
|
},
|
|
};
|
|
}
|
|
const kind = schema_js_1.s.enum(...KINDS);
|
|
const measurement = withUnit(schema_js_1.s.object({ "@type": kind, unit: schema_js_1.s.optional(schema_js_1.s.string({ min: 1 })) }, { unknownKeys: "reject" }));
|
|
const level = withUnit(schema_js_1.s.object({ "@type": kind, value: schema_js_1.s.number({ min: 0 }), unit: schema_js_1.s.optional(schema_js_1.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.
|
|
*/
|
|
exports.InventoryLevelSensor = (0, types_js_1.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: schema_js_1.s.object({
|
|
/** How the level is measured: { "@type": "Volume", unit: "MILLILITER" }, { "@type": "Count" }. */
|
|
measurement,
|
|
/** The id the Dash console gave for the product. */
|
|
replenishment: schema_js_1.s.object({ "@type": schema_js_1.s.enum("DashReplenishmentId"), value: schema_js_1.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 } : {};
|
|
},
|
|
});
|