"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AlexaInterface = void 0; const Capability_js_1 = require("../device/Capability.js"); const index_js_1 = require("../registry/index.js"); const resources_js_1 = require("../registry/resources.js"); /** * A capability as 1.x declares it: device.addCapability(type, options), then the add and set methods below. It is a * Capability, so what the methods set reaches discovery the same way as the options of device.add(). Nothing is * refused here except an interface name the registry does not have: what Alexa would reject is logged by the bridge * when it answers a discovery. */ class AlexaInterface extends Capability_js_1.Capability { constructor(type, retrievable = true, proactivelyReported = false, instance = "") { super(index_js_1.registry.get(type), { retrievable, proactivelyReported, instance, options: {} }); } /** The namespace of the interface, which is the value of its AlexaInterfaceType member. */ get type() { return this.descriptor.namespace; } addActionMapping(mapping) { var _a; const semantics = ((_a = this.options).semantics ?? (_a.semantics = {})); (semantics.actionMappings ?? (semantics.actionMappings = [])).push(mapping.toJSON()); if (mapping.deprecation) this.notes.push(mapping.deprecation); } addFriendlyName(name, locale) { this.friendlyNames.push((0, resources_js_1.text)(name, locale)); } /** * The modes of a ModeController, as { value, modeResources } objects. A mode given as a string is announced as * { value } and noted: Alexa wants friendly names for it. ordered is true unless options.ordered says otherwise, * as 1.x announced every mode list; with device.add() the default is false. */ addSupportedModes(modes, options = {}) { this.options.ordered = options.ordered ?? true; this.options.supportedModes = modes.map((mode) => { if (typeof mode !== "string") return { value: mode.value, friendlyNames: (mode.modeResources?.friendlyNames ?? []) }; this.notes.push(`the mode ${mode} was given as a string, pass { value, modeResources }`); return { value: mode, friendlyNames: [] }; }); } setInstance(name) { this.instance = name; } getType() { return this.type; } /** @deprecated The same as getType(). */ getTypeString() { return this.type; } /** @deprecated Read descriptor.version. */ getVersion() { return this.descriptor.version; } /** @deprecated Read the keys of descriptor.properties. */ getProps() { return Object.keys(this.descriptor.properties); } getJSON() { return super.toJSON(); } // 1.x callers corrected the discovery JSON by replacing getJSON on the object: discovery goes through it toJSON() { return this.getJSON(); } } exports.AlexaInterface = AlexaInterface;