"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EqualizerController = void 0; const schema_js_1 = require("../schema.js"); const types_js_1 = require("../types.js"); const BANDS = ["BASS", "MIDRANGE", "TREBLE"]; const MODES = ["MOVIE", "MUSIC", "NIGHT", "SPORT", "TV"]; const band = schema_js_1.s.enum(...BANDS); const level = schema_js_1.s.number({ integer: true }); /** * The bands of an equalizer, its modes, or both. Discovery lists bands for a device declared with bands and mode * for one declared with modes. A band or a mode the device does not have is answered with INVALID_VALUE. */ exports.EqualizerController = (0, types_js_1.defineInterface)({ namespace: "Alexa.EqualizerController", version: "3", doc: "https://developer.amazon.com/docs/alexaplus/device-apis/alexa-equalizercontroller.html", kind: "controller", tier: 2, instanced: false, properties: { bands: { name: "bands", value: schema_js_1.s.array(schema_js_1.s.object({ name: band, value: level })) }, mode: { name: "mode", value: schema_js_1.s.enum(...MODES) }, }, directives: { SetMode: { name: "SetMode", payload: schema_js_1.s.object({ mode: schema_js_1.s.enum(...MODES) }) }, SetBands: { name: "SetBands", payload: schema_js_1.s.object({ bands: schema_js_1.s.array(schema_js_1.s.object({ name: band, value: level }), { min: 1 }) }) }, AdjustBands: { name: "AdjustBands", payload: schema_js_1.s.object({ bands: schema_js_1.s.array(schema_js_1.s.object({ name: band, levelDelta: schema_js_1.s.optional(level), levelDirection: schema_js_1.s.enum("UP", "DOWN") }), { min: 1 }), }), note: "without levelDelta the band moves by the step the device has for it", }, ResetBands: { name: "ResetBands", payload: schema_js_1.s.object({ bands: schema_js_1.s.array(schema_js_1.s.object({ name: band }), { min: 1 }) }) }, }, options: schema_js_1.s.object({ /** The bands of the device and the levels they take. Left out for a device that has modes only. */ bands: schema_js_1.s.optional(schema_js_1.s.object({ supported: schema_js_1.s.array(band, { min: 1 }), range: schema_js_1.s.object({ minimum: level, maximum: level }, { unknownKeys: "reject" }), }, { unknownKeys: "reject" })), /** Left out for a device that has bands only. */ modes: schema_js_1.s.optional(schema_js_1.s.array(schema_js_1.s.enum(...MODES), { min: 1 })), }, { unknownKeys: "reject" }), // A capability declared the 1.x way has neither; check() says so, discovery lists both properties discovery({ options: { bands, modes } }) { if (!bands && !modes) return {}; return { supported: [...(bands ? ["bands"] : []), ...(modes ? ["mode"] : [])], configurations: { ...(bands && { bands: { supported: bands.supported.map((name) => ({ name })), range: bands.range } }), ...(modes && { modes: { supported: modes.map((name) => ({ name })) } }), }, }; }, validate(capability) { const { bands, modes = [] } = capability.options; if (!bands && modes.length === 0) throw new types_js_1.DeclarationError(capability, "needs bands, modes or both: declare what the equalizer has"); if (bands && bands.range.maximum <= bands.range.minimum) { throw new types_js_1.DeclarationError(capability, `bands.range.maximum ${bands.range.maximum} is not above bands.range.minimum ${bands.range.minimum}`); } const lists = [bands?.supported ?? [], modes]; for (const list of lists) { const twice = list.find((entry, i) => list.indexOf(entry) !== i); if (twice) throw new types_js_1.DeclarationError(capability, `${twice} is listed twice`); } }, });