Alex2Node/dist/cjs/registry/interfaces/EqualizerController.js
David d7dfc5b122 registry: Speaker, StepSpeaker, EqualizerController, PlaybackController, PlaybackStateReporter, InputController, ChannelController
Seven descriptors written from their pages replace seven stubs. All are version 3; 1.5.2 announced Speaker,
StepSpeaker, EqualizerController and PlaybackStateReporter as version 1, and all but ChannelController without
a property. StepSpeaker has no properties object in discovery and PlaybackController one without fields, next
to supportedOperations; a directive for an operation the device did not list is answered with
INVALID_DIRECTIVE. The equalizer declares bands, modes or both under "configurations", a TV its inputs from
the 61 names of the page.

Not described: the lineup of ChannelController, whose discovery example the page folds away. The discovery
examples of InputController spell one key "friendNames"; the fixtures have friendlyNames, as its table does.
62 examples of the six pages are saved as fixtures. 241 tests pass, 215 before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-28 20:54:53 +00:00

72 lines
3.9 KiB
JavaScript

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