import { Capability } from "../device/Capability.js"; import { registry } from "../registry/index.js"; import { text } from "../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. */ export class AlexaInterface extends Capability { constructor(type, retrievable = true, proactivelyReported = false, instance = "") { super(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(text(name, locale)); } /** The modes of a ModeController, as { value, modeResources } objects. */ addSupportedModes(modes) { this.options.supportedModes = modes; } 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(); } }