"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 } : {}; }, });