"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimpleEventSource = void 0; const events_js_1 = require("../events.js"); const resources_js_1 = require("../resources.js"); const schema_js_1 = require("../schema.js"); const types_js_1 = require("../types.js"); /** * A button of a remote, or anything else that routines start on. Each instance is one button with the events it * has, a single and a double push; device.raise(SimpleEventSource, "Event", { id }, { instance }) says that one * happened. Alexa wants the instance to be unique among all endpoints, "preferably a version 4 UUID". * * The page folds its discovery example away. The capability is announced with the fields of its table and without a * properties object, as the interface has no property. */ exports.SimpleEventSource = (0, types_js_1.defineInterface)({ namespace: "Alexa.SimpleEventSource", version: "1.0", doc: "https://developer.amazon.com/docs/alexaplus/device-apis/alexa-simpleeventsource.html", kind: "eventSource", tier: 2, instanced: true, properties: {}, directives: {}, events: { Event: { name: "Event", /** id: the id of one of the supportedEvents of the instance. */ payload: schema_js_1.s.object({ id: schema_js_1.s.string({ min: 1 }), timestamp: events_js_1.timestamp }), topic: "proactive", }, }, options: schema_js_1.s.object({ /** For a REMOTE the names are assets of the catalog: Alexa.Button.SinglePush, Alexa.Gesture.Tap. */ supportedEvents: schema_js_1.s.array(schema_js_1.s.object({ id: schema_js_1.s.string({ min: 1 }), friendlyNames: resources_js_1.labels }, { unknownKeys: "reject" }), { min: 1 }), }, { unknownKeys: "reject" }), // A capability declared the 1.x way has no events; check() says so discovery: ({ options: { supportedEvents } }) => ({ properties: false, ...(supportedEvents && { configuration: { supportedEvents } }), }), validate(capability) { const { supportedEvents } = capability.options; const ids = supportedEvents.map(({ id }) => id); // "The first friendly name in the array must be unique per instance of the capability." const names = supportedEvents.map(({ friendlyNames: [first] }) => (0, resources_js_1.shownAs)(first)); const twice = (list) => list.find((entry, i) => list.indexOf(entry) !== i); if (twice(ids)) throw new types_js_1.DeclarationError(capability, `the event ${twice(ids)} is listed twice`); if (twice(names)) throw new types_js_1.DeclarationError(capability, `two events have ${twice(names)} as their first friendly name, the Alexa app shows an event by it`); }, });