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>
46 lines
2.4 KiB
JavaScript
46 lines
2.4 KiB
JavaScript
import { s } from "../schema.js";
|
|
import { DeclarationError, defineInterface } from "../types.js";
|
|
/** alexa-inputcontroller.html, "Input property values". */
|
|
export const INPUTS = [
|
|
"AUX 1", "AUX 2", "AUX 3", "AUX 4", "AUX 5", "AUX 6", "AUX 7", "BLURAY", "CABLE", "CD", "COAX 1", "COAX 2",
|
|
"COMPOSITE 1", "DVD", "GAME", "HD RADIO", "HDMI 1", "HDMI 2", "HDMI 3", "HDMI 4", "HDMI 5", "HDMI 6", "HDMI 7",
|
|
"HDMI 8", "HDMI 9", "HDMI 10", "HDMI ARC", "INPUT 1", "INPUT 2", "INPUT 3", "INPUT 4", "INPUT 5", "INPUT 6",
|
|
"INPUT 7", "INPUT 8", "INPUT 9", "INPUT 10", "IPOD", "LINE 1", "LINE 2", "LINE 3", "LINE 4", "LINE 5", "LINE 6",
|
|
"LINE 7", "MEDIA PLAYER", "OPTICAL 1", "OPTICAL 2", "PHONO", "PLAYSTATION", "PLAYSTATION 3", "PLAYSTATION 4",
|
|
"SATELLITE", "SMARTCAST", "TUNER", "TV", "USB DAC", "VIDEO 1", "VIDEO 2", "VIDEO 3", "XBOX",
|
|
];
|
|
const input = s.oneOf(INPUTS, "an input like HDMI 1");
|
|
/**
|
|
* The input a TV or a receiver shows. The inputs of the device are on the capability itself, as the discovery
|
|
* example of the page has them; its table calls them a configuration object.
|
|
*/
|
|
export const InputController = defineInterface({
|
|
namespace: "Alexa.InputController",
|
|
version: "3",
|
|
doc: "https://developer.amazon.com/docs/alexaplus/device-apis/alexa-inputcontroller.html",
|
|
kind: "controller",
|
|
tier: 2,
|
|
instanced: false,
|
|
properties: {
|
|
input: { name: "input", value: input },
|
|
},
|
|
directives: {
|
|
SelectInput: { name: "SelectInput", payload: s.object({ input }) },
|
|
},
|
|
options: s.object({
|
|
/** friendlyNames: what the user calls the input, "Cable" for HDMI 2. */
|
|
inputs: s.array(s.object({ name: input, friendlyNames: s.optional(s.array(s.string({ min: 1 }))) }, { unknownKeys: "reject" }), { min: 1 }),
|
|
}, { unknownKeys: "reject" }),
|
|
// A capability declared the 1.x way has no inputs; check() says so
|
|
discovery: ({ options: { inputs } }) => (inputs ? { topLevel: { inputs } } : {}),
|
|
validate(capability) {
|
|
const names = capability.options.inputs.map(({ name }) => name);
|
|
const called = capability.options.inputs.flatMap(({ friendlyNames = [] }) => friendlyNames);
|
|
const lists = [names, called];
|
|
for (const list of lists) {
|
|
const twice = list.find((entry, i) => list.indexOf(entry) !== i);
|
|
if (twice)
|
|
throw new DeclarationError(capability, `${twice} is listed twice, a name stands for one input`);
|
|
}
|
|
},
|
|
});
|