registry: RangeController, ModeController, ToggleController with resources, presets and semantics
The three generic controllers are described in full and leave the stub table (62 stubs remain). A declaration
takes an instance name, friendly names from text() and asset(), and the options of the interface: range, unit and
presets for a range; supportedModes and ordered for a mode; semantics() for all three, with actions mapped to
directives and states mapped to a value or a range of values.
Refused at device.add(), each with the endpoint, interface and instance in the message: no instance name or no
friendly name; an instance declared twice; a first friendly name or a phrase used by another capability of the
endpoint; a reserved word, an asset id that is not in the catalog; range.max not above range.min; a preset off the
precision grid or outside the range; fewer than two modes or a mode listed twice; a mapping to a directive the
interface does not have, to a payload that does not fit, to a mode that is not listed, to AdjustMode on modes
that are not ordered; SetEcoOn, SetEcoOff, EcoOn and EcoOff on anything but a toggle.
For 1.x callers: Alexa.RangeController lists rangeValue (1.5.2 sent supported: []); addSupportedModes() announces
a mode given as a string as { value } and notes it, and takes { ordered: false } as a second argument, the default
stays true as 1.5.2 sent it (device.add() defaults to false). Declared the 1.x way, the zoo fan and curtain give
the same JSON as before.
Tests: the zoo blind, whose range, unit and semantics were written by hand into the JSON of 1.5.2, is declared
with device.add() and equals that JSON plus the Alexa capability; five capability objects of Amazon's examples
are reproduced the same way. 27 examples of four pages added. npm test: 108 pass (was 85) in 10.5-11.3 s, also on
Node 18.20.8 and 20.20.2.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
c492ef74d1
commit
2558e21787
80 changed files with 3131 additions and 107 deletions
|
|
@ -5,7 +5,7 @@ const { test } = require("node:test");
|
|||
const assert = require("node:assert/strict");
|
||||
const {
|
||||
Alex2MQTT, ActionMapping, Alexa, AlexaActions, AlexaInterfaceType, BrightnessController, DisplayCategory, EndpointHealth,
|
||||
PowerController, TemperatureSensor, registry,
|
||||
ModeController, PowerController, RangeController, TemperatureSensor, ToggleController, asset, registry, semantics, text,
|
||||
} = require("alex2node");
|
||||
const interfaces = require("../fixtures/interfaces.js");
|
||||
const { endpoint } = require("../helpers/endpoint.js");
|
||||
|
|
@ -23,13 +23,26 @@ async function discover(alexa, root) {
|
|||
return alexa.on(`${root}/discover_r`)[before];
|
||||
}
|
||||
|
||||
for (const { namespace, page, declared } of interfaces) {
|
||||
test(`${namespace}: device.add() gives the capability object of ${page}.html`, () => {
|
||||
for (const { options, as: [example, n = 0] } of declared) {
|
||||
const capability = endpoint().add(registry.get(namespace), options);
|
||||
assert.deepEqual(capability.toJSON(), capabilities(page, namespace, example)[n], `${example}[${n}]`);
|
||||
}
|
||||
});
|
||||
// A device with the fields of a zoo endpoint and no capabilities.
|
||||
function likeTheZoo(endpointId) {
|
||||
const accepted = zoo(endpointId);
|
||||
const device = endpoint(endpointId, accepted.friendlyName, accepted.displayCategories);
|
||||
device.setDescription(accepted.description);
|
||||
device.setManufacturerName(accepted.manufacturerName);
|
||||
device.setManufacturer(accepted.additionalAttributes.manufacturer);
|
||||
device.setModel(accepted.additionalAttributes.model);
|
||||
return device;
|
||||
}
|
||||
|
||||
for (const { namespace, page: own, declared } of interfaces) {
|
||||
for (const { options, example, page = own, n = 0 } of declared) {
|
||||
test(`${namespace}: device.add() gives the capability object of ${page}.html, ${example}${n > 0 ? ` (${n})` : ""}`, () => {
|
||||
const device = endpoint();
|
||||
const capability = device.add(registry.get(namespace), options);
|
||||
assert.deepEqual(capability.toJSON(), capabilities(page, namespace, example)[n]);
|
||||
assert.deepEqual(device.check(), []);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test("the fields of a capability object are in the order of the examples: type, interface, version, properties", () => {
|
||||
|
|
@ -111,17 +124,115 @@ test("1.x declarations are announced as 1.5.2 announced them, with the Alexa int
|
|||
};
|
||||
for (const [endpointId, declare] of Object.entries(declarations)) {
|
||||
const accepted = zoo(endpointId);
|
||||
const device = endpoint(endpointId, accepted.friendlyName, accepted.displayCategories);
|
||||
device.setDescription(accepted.description);
|
||||
device.setManufacturerName(accepted.manufacturerName);
|
||||
device.setManufacturer(accepted.additionalAttributes.manufacturer);
|
||||
device.setModel(accepted.additionalAttributes.model);
|
||||
const device = likeTheZoo(endpointId);
|
||||
declare(device);
|
||||
assert.deepEqual(device.getJSON(), { ...accepted, capabilities: [...accepted.capabilities, ALEXA] }, endpointId);
|
||||
assert.deepEqual(device.check(), [], endpointId);
|
||||
}
|
||||
});
|
||||
|
||||
test("a RangeController blind declared with device.add() is the zoo's blind, whose JSON was written by hand", () => {
|
||||
const blinds = likeTheZoo("zoo-blinds");
|
||||
blinds.add(RangeController, {
|
||||
instance: "Blind.Lift",
|
||||
friendlyNames: [asset("Alexa.Setting.Opening")],
|
||||
range: { min: 0, max: 100, precision: 1 },
|
||||
unit: "Alexa.Unit.Percent",
|
||||
semantics: semantics()
|
||||
.action("Close", "SetRangeValue", { rangeValue: 0 })
|
||||
.action("Open", "SetRangeValue", { rangeValue: 100 })
|
||||
.action("Lower", "AdjustRangeValue", { rangeValueDelta: -10, rangeValueDeltaDefault: false })
|
||||
.action("Raise", "AdjustRangeValue", { rangeValueDelta: 10, rangeValueDeltaDefault: false })
|
||||
.state("Closed", 0)
|
||||
.stateRange("Open", 1, 100),
|
||||
retrievable: true,
|
||||
proactivelyReported: true,
|
||||
});
|
||||
const accepted = zoo("zoo-blinds");
|
||||
assert.deepEqual(blinds.getJSON(), { ...accepted, capabilities: [...accepted.capabilities, ALEXA] });
|
||||
assert.deepEqual(blinds.check(), []);
|
||||
});
|
||||
|
||||
test("the zoo's fan and curtain declared with device.add(): a ModeController and a ToggleController with semantics", () => {
|
||||
const fan = likeTheZoo("zoo-fan");
|
||||
fan.add(PowerController, { proactivelyReported: true });
|
||||
fan.add(ModeController, {
|
||||
instance: "Fan.Speed",
|
||||
friendlyNames: [text("Speed")],
|
||||
supportedModes: ["Low", "Medium", "High"].map((name) => ({ value: `Speed.${name}`, friendlyNames: [text(name)] })),
|
||||
ordered: true,
|
||||
proactivelyReported: true,
|
||||
});
|
||||
assert.deepEqual(fan.getJSON().capabilities, [...zoo("zoo-fan").capabilities, ALEXA]);
|
||||
|
||||
const curtain = likeTheZoo("zoo-curtain");
|
||||
curtain.add(PowerController, { proactivelyReported: true });
|
||||
curtain.add(ToggleController, {
|
||||
instance: "Zoo.Shade",
|
||||
friendlyNames: [text("Shade")],
|
||||
semantics: semantics().action("Close", "TurnOn").action("Open", "TurnOff"),
|
||||
proactivelyReported: true,
|
||||
});
|
||||
assert.deepEqual(curtain.getJSON().capabilities, [...zoo("zoo-curtain").capabilities, ALEXA]);
|
||||
});
|
||||
|
||||
test("ModeController: the modes are not ordered unless the declaration says so; a mode is declared in either form", () => {
|
||||
const modes = endpoint("washer-1", "Washer", ["WASHER"]).add(ModeController, {
|
||||
instance: "Washer.WashCycle",
|
||||
friendlyNames: [asset("Alexa.Setting.WashCycle")],
|
||||
supportedModes: [
|
||||
{ value: "WashCycle.Normal", friendlyNames: [text("Normal"), text("Cottons")] },
|
||||
{ value: "WashCycle.Delicates", modeResources: { friendlyNames: [asset("Alexa.Value.Delicate"), text("Knits")] } },
|
||||
],
|
||||
});
|
||||
assert.deepEqual(modes.toJSON().configuration, {
|
||||
ordered: false,
|
||||
supportedModes: [
|
||||
{ value: "WashCycle.Normal", modeResources: { friendlyNames: [text("Normal"), text("Cottons")] } },
|
||||
{ value: "WashCycle.Delicates", modeResources: { friendlyNames: [asset("Alexa.Value.Delicate"), text("Knits")] } },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("1.x addSupportedModes: ordered as 1.x announced it, or as the second argument says; a string becomes { value }", () => {
|
||||
const fan = endpoint("fan-1", "Fan", ["FAN"]);
|
||||
const named = (value) => ({ value, modeResources: { friendlyNames: [{ "@type": "text", value: { text: value, locale: "en-US" } }] } });
|
||||
const speed = fan.addCapability(AlexaInterfaceType.MODE_CONTROLLER, { instance: "Fan.Speed" });
|
||||
speed.addFriendlyName("Speed", "en-US");
|
||||
speed.addSupportedModes([named("Low"), named("High")]);
|
||||
assert.equal(speed.getJSON().configuration.ordered, true);
|
||||
|
||||
const source = fan.addCapability(AlexaInterfaceType.MODE_CONTROLLER, { instance: "Fan.Mode" });
|
||||
source.addFriendlyName("Mode", "en-US");
|
||||
source.addSupportedModes([named("Auto"), named("On")], { ordered: false });
|
||||
assert.deepEqual(source.getJSON().configuration, { ordered: false, supportedModes: [named("Auto"), named("On")] });
|
||||
assert.deepEqual(fan.check(), []);
|
||||
|
||||
const plain = fan.addCapability(AlexaInterfaceType.MODE_CONTROLLER, { instance: "Fan.Timer" });
|
||||
plain.addFriendlyName("Countdown", "en-US");
|
||||
plain.addSupportedModes(["Short", named("Long")]);
|
||||
assert.deepEqual(plain.getJSON().configuration.supportedModes, [{ value: "Short" }, named("Long")]);
|
||||
assert.deepEqual(fan.check(), [
|
||||
'fan-1: Alexa.ModeController "Fan.Timer": supportedModes[0].friendlyNames: expected a list with 1 or more entries, got []',
|
||||
'fan-1: Alexa.ModeController "Fan.Timer": the mode Short was given as a string, pass { value, modeResources }',
|
||||
]);
|
||||
});
|
||||
|
||||
test("a 1.x RangeController has no way to give its range: announced as 1.5.2 did, with its property now, and check() says it", () => {
|
||||
const blinds = endpoint("blinds-1", "Blinds", ["INTERIOR_BLIND"]);
|
||||
const lift = blinds.addCapability(AlexaInterfaceType.RANGE_CONTROLLER, { instance: "Blind.Lift", proactivelyReported: true });
|
||||
lift.addFriendlyName("Lift", "en-US");
|
||||
assert.deepEqual(lift.getJSON(), {
|
||||
type: "AlexaInterface",
|
||||
interface: "Alexa.RangeController",
|
||||
instance: "Blind.Lift",
|
||||
version: "3",
|
||||
properties: { supported: [{ name: "rangeValue" }], proactivelyReported: true, retrievable: true },
|
||||
capabilityResources: { friendlyNames: [text("Lift")] },
|
||||
});
|
||||
assert.deepEqual(blinds.check(), ['blinds-1: Alexa.RangeController "Blind.Lift": range: expected an object with min, max, precision, got nothing']);
|
||||
});
|
||||
|
||||
test("registerDevice: every endpoint ends with the Alexa interface; alexaInterface: false leaves it out", async () => {
|
||||
const { alexa, bridge } = await setup(Alex2MQTT, "root");
|
||||
const lamp = bridge.registerDevice("Lamp", "lamp-1", DisplayCategory.LIGHT);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
const { test } = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const {
|
||||
Alex2MQTT, AlexaInterfaceType, BrightnessController, DeclarationError, EndpointHealth, PowerController, TemperatureSensor, registry,
|
||||
ActionMapping, Alex2MQTT, AlexaActions, AlexaInterfaceType, BrightnessController, DeclarationError, EndpointHealth, ModeController,
|
||||
PowerController, RangeController, TemperatureSensor, ToggleController, asset, registry, semantics, text,
|
||||
} = require("alex2node");
|
||||
const { endpoint } = require("../helpers/endpoint.js");
|
||||
const { setup, sleep } = require("../helpers/harness.js");
|
||||
|
|
@ -98,8 +99,11 @@ test("device.add refuses an option the interface does not have and a value that
|
|||
});
|
||||
|
||||
test("an endpoint takes 100 capabilities, the ones the library adds among them", () => {
|
||||
const switches = (device) => {
|
||||
for (let n = 1; n <= 98; n += 1) device.add(ToggleController, { instance: `Panel.Switch${n}`, friendlyNames: [text(`Switch ${n}`)] });
|
||||
};
|
||||
const panel = endpoint("panel-1", "Panel", ["OTHER"]);
|
||||
for (let n = 1; n <= 98; n += 1) panel.addCapability(AlexaInterfaceType.TOGGLE_CONTROLLER, { instance: `Panel.Switch${n}` });
|
||||
switches(panel);
|
||||
panel.add(PowerController);
|
||||
assert.equal(panel.getJSON().capabilities.length, 100);
|
||||
assert.deepEqual(panel.check(), []);
|
||||
|
|
@ -114,7 +118,7 @@ test("an endpoint takes 100 capabilities, the ones the library adds among them",
|
|||
// With Alexa.EndpointHealth added for the device there is room for 98
|
||||
const health = endpoint("panel-2", "Panel", ["OTHER"]);
|
||||
health.endpointHealth = true;
|
||||
for (let n = 1; n <= 98; n += 1) health.addCapability(AlexaInterfaceType.TOGGLE_CONTROLLER, { instance: `Panel.Switch${n}` });
|
||||
switches(health);
|
||||
assert.equal(refused(() => health.add(PowerController)).message, "panel-2: 101 capabilities, an endpoint takes 100");
|
||||
assert.doesNotThrow(() => health.add(EndpointHealth));
|
||||
});
|
||||
|
|
@ -127,12 +131,166 @@ test("check() lists what is wrong with a device declared the 1.x way, one line f
|
|||
fan.addCapability(AlexaInterfaceType.POWER_CONTROLLER, { instance: "Fan.Power" });
|
||||
fan.addCapability(AlexaInterfaceType.TOGGLE_CONTROLLER, { instance: "Fan.Oscillate" });
|
||||
fan.addCapability(AlexaInterfaceType.TOGGLE_CONTROLLER, { instance: "Fan.Oscillate" });
|
||||
fan.addCapability(AlexaInterfaceType.TOGGLE_CONTROLLER).addFriendlyName("Light", "en-US");
|
||||
fan.addCapability(AlexaInterfaceType.RANGE_CONTROLLER, { instance: "Fan.Speed" }).addFriendlyName("Speed", "en-US");
|
||||
const mode = fan.addCapability(AlexaInterfaceType.MODE_CONTROLLER, { instance: "Fan.Mode" });
|
||||
mode.addFriendlyName("Volume", "en-US");
|
||||
mode.addSupportedModes(["Auto"]);
|
||||
const direction = fan.addCapability(AlexaInterfaceType.TOGGLE_CONTROLLER, { instance: "Fan.Direction" });
|
||||
direction.addFriendlyName("Speed", "en-US");
|
||||
direction.addActionMapping(new ActionMapping([AlexaActions.Open], "Reverse"));
|
||||
assert.deepEqual(fan.check(), [
|
||||
'fan-1: "VEHICLE" is not a display category',
|
||||
'fan-1: Alexa.PowerController "Fan.Power": takes no instance name: an endpoint has the interface once',
|
||||
'fan-1: Alexa.ToggleController "Fan.Oscillate": needs a friendly name, from text() or asset()',
|
||||
'fan-1: Alexa.ToggleController "Fan.Oscillate": the instance is declared twice',
|
||||
"fan-1: Alexa.ToggleController: needs an instance name, like Blind.Lift",
|
||||
'fan-1: Alexa.RangeController "Fan.Speed": range: expected an object with min, max, precision, got nothing',
|
||||
'fan-1: Alexa.ModeController "Fan.Mode": friendlyNames[0].value.text: "Volume" is a reserved word, not to be used as a friendly name',
|
||||
'fan-1: Alexa.ModeController "Fan.Mode": the mode Auto was given as a string, pass { value, modeResources }',
|
||||
'fan-1: Alexa.ToggleController "Fan.Direction": the first friendly name, Speed, is the first of Alexa.RangeController "Fan.Speed" too',
|
||||
]);
|
||||
assert.equal(fan.getJSON().capabilities.length, 4, "announced all the same");
|
||||
assert.equal(fan.getJSON().capabilities.length, 8, "announced all the same");
|
||||
});
|
||||
|
||||
// A blind with a lift from 0 to 100: what each case below declares on top of it
|
||||
const LIFT = { instance: "Blind.Lift", friendlyNames: [asset("Alexa.Setting.Opening")], range: { min: 0, max: 100, precision: 5 } };
|
||||
const POSITION = {
|
||||
instance: "Blind.Position",
|
||||
friendlyNames: [text("Position")],
|
||||
supportedModes: [
|
||||
{ value: "Position.Up", friendlyNames: [asset("Alexa.Value.Open")] },
|
||||
{ value: "Position.Down", friendlyNames: [asset("Alexa.Value.Close")] },
|
||||
],
|
||||
};
|
||||
const TILT = { instance: "Blind.Tilt", friendlyNames: [text("Tilt")] };
|
||||
const without = (options, ...keys) => Object.fromEntries(Object.entries(options).filter(([key]) => !keys.includes(key)));
|
||||
|
||||
test("a generic controller needs an instance name and a friendly name, and each instance is declared once", () => {
|
||||
const cases = [
|
||||
[RangeController, without(LIFT, "instance"), "Alexa.RangeController: needs an instance name, like Blind.Lift"],
|
||||
[ModeController, without(POSITION, "instance"), "Alexa.ModeController: needs an instance name, like Blind.Lift"],
|
||||
[ToggleController, { ...TILT, instance: "" }, "Alexa.ToggleController: needs an instance name, like Blind.Lift"],
|
||||
[RangeController, without(LIFT, "friendlyNames"), 'Alexa.RangeController "Blind.Lift": needs a friendly name, from text() or asset()'],
|
||||
[ModeController, { ...POSITION, friendlyNames: [] }, 'Alexa.ModeController "Blind.Position": needs a friendly name, from text() or asset()'],
|
||||
[ToggleController, without(TILT, "friendlyNames"), 'Alexa.ToggleController "Blind.Tilt": needs a friendly name, from text() or asset()'],
|
||||
];
|
||||
for (const [descriptor, options, message] of cases) {
|
||||
assert.equal(refused(() => endpoint("blinds-1").add(descriptor, options)).message, `blinds-1: ${message}`);
|
||||
}
|
||||
|
||||
const blinds = endpoint("blinds-1");
|
||||
blinds.add(ToggleController, TILT);
|
||||
assert.equal(
|
||||
refused(() => blinds.add(ToggleController, { ...TILT, friendlyNames: [text("Slats")] })).message,
|
||||
'blinds-1: Alexa.ToggleController "Blind.Tilt": the instance is declared twice'
|
||||
);
|
||||
// The same instance name under another interface is another capability
|
||||
blinds.add(RangeController, { ...LIFT, instance: "Blind.Tilt" });
|
||||
assert.equal(blinds.getCapabilities().length, 2);
|
||||
});
|
||||
|
||||
test("friendly names: an asset of the catalog or a text with a locale, no reserved word, the first one once on the endpoint", () => {
|
||||
const named = (...friendlyNames) => () => endpoint("blinds-1").add(ToggleController, { ...TILT, friendlyNames });
|
||||
const cases = [
|
||||
[named(text("volume")), 'friendlyNames[0].value.text: "volume" is a reserved word, not to be used as a friendly name'],
|
||||
[named(text("Tilt"), text("Night Light")), 'friendlyNames[1].value.text: "Night Light" is a reserved word, not to be used as a friendly name'],
|
||||
[named(asset("Alexa.Setting.Tilt")), 'friendlyNames[0].value.assetId: expected an id of the global Alexa catalog, like Alexa.Setting.Opening, got "Alexa.Setting.Tilt"'],
|
||||
[named(text("Tilt", "english")), 'friendlyNames[0].value.locale: expected a locale like en-US, got "english"'],
|
||||
[named(text("")), 'friendlyNames[0].value.text: expected a string of 1 or more characters, got ""'],
|
||||
[named("Tilt"), 'friendlyNames[0]: expected a friendly name, from text() or asset(), got "Tilt"'],
|
||||
[named({ "@type": "name", value: "Tilt" }), 'friendlyNames[0].@type: expected text | asset, got "name"'],
|
||||
];
|
||||
for (const [declare, message] of cases) assert.equal(refused(declare).message, `blinds-1: Alexa.ToggleController "Blind.Tilt": ${message}`);
|
||||
|
||||
const blinds = endpoint("blinds-1");
|
||||
blinds.add(RangeController, LIFT);
|
||||
blinds.add(ToggleController, TILT);
|
||||
assert.equal(
|
||||
refused(() => blinds.add(ModeController, { ...POSITION, friendlyNames: [text("tilt"), text("Position")] })).message,
|
||||
'blinds-1: Alexa.ModeController "Blind.Position": the first friendly name, tilt, is the first of Alexa.ToggleController "Blind.Tilt" too'
|
||||
);
|
||||
assert.equal(
|
||||
refused(() => blinds.add(ModeController, { ...POSITION, friendlyNames: [asset("Alexa.Setting.Opening")] })).message,
|
||||
'blinds-1: Alexa.ModeController "Blind.Position": the first friendly name, Alexa.Setting.Opening, is the first of Alexa.RangeController "Blind.Lift" too'
|
||||
);
|
||||
// Second names may repeat, and the same text in another language is another name
|
||||
blinds.add(ModeController, { ...POSITION, friendlyNames: [text("Tilt", "en-GB"), text("Tilt")] });
|
||||
assert.equal(blinds.getCapabilities().length, 3);
|
||||
});
|
||||
|
||||
test("RangeController: a range, presets on its grid, a unit of measure", () => {
|
||||
const lift = (options) => () => endpoint("blinds-1").add(RangeController, { ...LIFT, ...options });
|
||||
const preset = (value) => ({ value, friendlyNames: [text("Half")] });
|
||||
const cases = [
|
||||
[() => endpoint("blinds-1").add(RangeController, without(LIFT, "range")), "range: expected an object with min, max, precision, got nothing"],
|
||||
[lift({ range: { min: 0, max: 100 } }), "range.precision: expected a number greater than 0, got nothing"],
|
||||
[lift({ range: { min: 0, max: 100, precision: 0 } }), "range.precision: expected a number greater than 0, got 0"],
|
||||
[lift({ range: { min: 0, max: 100, step: 5 } }), "range.step: unknown key, the known ones are min, max, precision"],
|
||||
[lift({ range: { min: 100, max: 0, precision: 5 } }), "range.max 0 is not above range.min 100"],
|
||||
[lift({ presets: [preset(50), preset(52)] }), "the preset 52 is not 0 + n x 5, up to 100"],
|
||||
[lift({ presets: [preset(105)] }), "the preset 105 is not 0 + n x 5, up to 100"],
|
||||
[lift({ presets: [{ value: 50 }] }), "presets[0].friendlyNames: expected a list with 1 or more entries, got nothing"],
|
||||
[lift({ presets: [{ value: 50, friendlyNames: [text("Timer")] }] }), 'presets[0].friendlyNames[0].value.text: "Timer" is a reserved word, not to be used as a friendly name'],
|
||||
[lift({ unit: "Alexa.Unit.Percentage" }), 'unit: expected a unit of measure like Alexa.Unit.Percent, got "Alexa.Unit.Percentage"'],
|
||||
[lift({ preset: [] }), "preset: unknown key, the known ones are range, unit, presets, semantics"],
|
||||
[lift({ semantics: semantics().action("Open", "SetRangeValue", { rangeValue: 1000 }) }), "an action is mapped to SetRangeValue 1000, the range is 0 to 100"],
|
||||
];
|
||||
for (const [declare, message] of cases) assert.equal(refused(declare).message, `blinds-1: Alexa.RangeController "Blind.Lift": ${message}`);
|
||||
|
||||
// A grid that does not start at 0, and one of tenths
|
||||
const fan = endpoint("fan-1");
|
||||
fan.add(RangeController, { ...LIFT, range: { min: 1, max: 10, precision: 3 }, presets: [preset(1), preset(4), preset(10)] });
|
||||
fan.add(RangeController, {
|
||||
instance: "Fan.Angle",
|
||||
friendlyNames: [text("Angle")],
|
||||
range: { min: 0, max: 1, precision: 0.1 },
|
||||
presets: [{ value: 0.3, friendlyNames: [text("Narrow")] }, { value: 0.7, friendlyNames: [text("Wide")] }],
|
||||
});
|
||||
assert.equal(fan.getCapabilities().length, 2);
|
||||
});
|
||||
|
||||
test("ModeController: two modes or more, each once, and mappings to modes it has", () => {
|
||||
const position = (options) => () => endpoint("blinds-1").add(ModeController, { ...POSITION, ...options });
|
||||
const [up, down] = POSITION.supportedModes;
|
||||
const cases = [
|
||||
[() => endpoint("blinds-1").add(ModeController, without(POSITION, "supportedModes")), "supportedModes: expected a list with 2 or more entries, got nothing"],
|
||||
[position({ supportedModes: [up] }), /^supportedModes: expected a list with 2 or more entries, got \[\{"value":"Position\.Up"/],
|
||||
[position({ supportedModes: [up, down, up] }), "the mode Position.Up is listed twice"],
|
||||
[position({ supportedModes: [up, { value: "Position.Down" }] }), "supportedModes[1].friendlyNames: expected a list with 1 or more entries, got nothing"],
|
||||
[position({ supportedModes: [up, "Position.Down"] }), 'supportedModes[1]: expected a mode { value, friendlyNames }, got "Position.Down"'],
|
||||
[position({ ordered: "yes" }), 'ordered: expected true or false, got "yes"'],
|
||||
[position({ semantics: semantics().action("Open", "SetMode", { mode: "Position.Open" }) }), "an action is mapped to SetMode Position.Open, the modes are Position.Up, Position.Down"],
|
||||
[position({ semantics: semantics().state("Closed", "Position.Closed") }), "a state is mapped to Position.Closed, the modes are Position.Up, Position.Down"],
|
||||
[position({ semantics: semantics().action("Raise", "AdjustMode", { modeDelta: 1 }) }), "an action is mapped to AdjustMode, which needs ordered: true"],
|
||||
];
|
||||
for (const [declare, message] of cases) {
|
||||
const prefix = 'blinds-1: Alexa.ModeController "Blind.Position": ';
|
||||
if (typeof message === "string") assert.equal(refused(declare).message, prefix + message);
|
||||
else assert.match(refused(declare).message.slice(prefix.length), message);
|
||||
}
|
||||
|
||||
const ordered = position({ ordered: true, semantics: semantics().action("Raise", "AdjustMode", { modeDelta: -1 }) })();
|
||||
const unordered = position({})();
|
||||
const { AdjustMode } = ModeController.directives;
|
||||
assert.deepEqual([AdjustMode.when(ordered), AdjustMode.when(unordered)], [true, false], "Alexa sends AdjustMode to an ordered mode only");
|
||||
});
|
||||
|
||||
test("a phrase is mapped once on an endpoint, across its Range, Mode and Toggle capabilities", () => {
|
||||
const blinds = endpoint("blinds-1");
|
||||
blinds.add(RangeController, { ...LIFT, semantics: semantics().action(["Open", "Raise"], "SetRangeValue", { rangeValue: 100 }) });
|
||||
assert.equal(
|
||||
refused(() => blinds.add(ToggleController, { ...TILT, semantics: semantics().action("Close", "TurnOff").action("Open", "TurnOn") })).message,
|
||||
'blinds-1: Alexa.ToggleController "Blind.Tilt": Alexa.Actions.Open is mapped here and on Alexa.RangeController "Blind.Lift", an endpoint maps a phrase once'
|
||||
);
|
||||
assert.equal(
|
||||
refused(() => blinds.add(ModeController, { ...POSITION, semantics: semantics().action("Lower", "SetMode", { mode: "Position.Down" }).action(["Close", "Lower"], "SetMode", { mode: "Position.Down" }) })).message,
|
||||
'blinds-1: Alexa.ModeController "Blind.Position": Alexa.Actions.Lower is mapped twice, an endpoint maps a phrase once'
|
||||
);
|
||||
blinds.add(ToggleController, { ...TILT, semantics: semantics().action("Close", "TurnOff").action("Lower", "TurnOff") });
|
||||
|
||||
// Another endpoint maps the same phrases
|
||||
endpoint("blinds-2").add(ToggleController, { ...TILT, semantics: semantics().action("Open", "TurnOn") });
|
||||
});
|
||||
|
||||
test("a stub is declared like any interface and checked for nothing but being declared twice", () => {
|
||||
|
|
|
|||
13
test/fixtures/alexa-docs/alexa-discovery-objects/actionMapping.json
vendored
Normal file
13
test/fixtures/alexa-docs/alexa-discovery-objects/actionMapping.json
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"@type": "ActionsToDirective",
|
||||
"actions": [
|
||||
"Alexa.Actions.Close",
|
||||
"Alexa.Actions.Lower"
|
||||
],
|
||||
"directive": {
|
||||
"name": "SetRangeValue",
|
||||
"payload": {
|
||||
"rangeValue": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
51
test/fixtures/alexa-docs/alexa-discovery-objects/semantics.json
vendored
Normal file
51
test/fixtures/alexa-docs/alexa-discovery-objects/semantics.json
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"semantics": {
|
||||
"actionMappings": [
|
||||
{
|
||||
"@type": "ActionsToDirective",
|
||||
"actions": [
|
||||
"Alexa.Actions.Close",
|
||||
"Alexa.Actions.Lower"
|
||||
],
|
||||
"directive": {
|
||||
"name": "SetRangeValue",
|
||||
"payload": {
|
||||
"rangeValue": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "ActionsToDirective",
|
||||
"actions": [
|
||||
"Alexa.Actions.Open",
|
||||
"Alexa.Actions.Raise"
|
||||
],
|
||||
"directive": {
|
||||
"name": "SetRangeValue",
|
||||
"payload": {
|
||||
"rangeValue": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"stateMappings": [
|
||||
{
|
||||
"@type": "StatesToValue",
|
||||
"states": [
|
||||
"Alexa.States.Closed"
|
||||
],
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"@type": "StatesToRange",
|
||||
"states": [
|
||||
"Alexa.States.Open"
|
||||
],
|
||||
"range": {
|
||||
"minimumValue": 1,
|
||||
"maximumValue": 100
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
10
test/fixtures/alexa-docs/alexa-discovery-objects/stateMapping.json
vendored
Normal file
10
test/fixtures/alexa-docs/alexa-discovery-objects/stateMapping.json
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"@type": "StatesToRange",
|
||||
"states": [
|
||||
"Alexa.States.Open"
|
||||
],
|
||||
"range": {
|
||||
"minimumValue": 1,
|
||||
"maximumValue": 100
|
||||
}
|
||||
}
|
||||
23
test/fixtures/alexa-docs/alexa-modecontroller/AdjustMode.directive.json
vendored
Normal file
23
test/fixtures/alexa-docs/alexa-modecontroller/AdjustMode.directive.json
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"directive": {
|
||||
"header": {
|
||||
"namespace": "Alexa.ModeController",
|
||||
"instance": "Washer.WashTemperature",
|
||||
"name": "AdjustMode",
|
||||
"messageId": "Unique version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID",
|
||||
"cookie": {}
|
||||
},
|
||||
"payload": {
|
||||
"modeDelta": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
31
test/fixtures/alexa-docs/alexa-modecontroller/AdjustMode.response.json
vendored
Normal file
31
test/fixtures/alexa-docs/alexa-modecontroller/AdjustMode.response.json
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "Response",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token that matches the request",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {}
|
||||
},
|
||||
"context": {
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.ModeController",
|
||||
"instance": "Washer.WashTemperature",
|
||||
"name": "mode",
|
||||
"value": "WashTemperature.Warm",
|
||||
"timeOfSample": "2017-02-03T16:20:00.00Z",
|
||||
"uncertaintyInMilliseconds": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
43
test/fixtures/alexa-docs/alexa-modecontroller/ChangeReport.json
vendored
Normal file
43
test/fixtures/alexa-docs/alexa-modecontroller/ChangeReport.json
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "ChangeReport",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {
|
||||
"change": {
|
||||
"cause": {
|
||||
"type": "PHYSICAL_INTERACTION"
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.ModeController",
|
||||
"instance": "Washer.WashTemperature",
|
||||
"name": "mode",
|
||||
"value": "WashTemperature.Hot",
|
||||
"timeOfSample": "2024-02-03T17:10:50.52Z",
|
||||
"uncertaintyInMilliseconds": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"namespace": "Alexa.EndpointHealth",
|
||||
"name": "connectivity",
|
||||
"value": {
|
||||
"value": "OK"
|
||||
},
|
||||
"timeOfSample": "2024-02-03T17:08:20.12Z",
|
||||
"uncertaintyInMilliseconds": 10000
|
||||
}
|
||||
}
|
||||
23
test/fixtures/alexa-docs/alexa-modecontroller/SetMode.directive.json
vendored
Normal file
23
test/fixtures/alexa-docs/alexa-modecontroller/SetMode.directive.json
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"directive": {
|
||||
"header": {
|
||||
"namespace": "Alexa.ModeController",
|
||||
"instance": "Washer.WashCycle",
|
||||
"name": "SetMode",
|
||||
"messageId": "Unique version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID",
|
||||
"cookie": {}
|
||||
},
|
||||
"payload": {
|
||||
"mode": "WashCycle.Normal"
|
||||
}
|
||||
}
|
||||
}
|
||||
31
test/fixtures/alexa-docs/alexa-modecontroller/SetMode.response.json
vendored
Normal file
31
test/fixtures/alexa-docs/alexa-modecontroller/SetMode.response.json
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "Response",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token that matches the request",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {}
|
||||
},
|
||||
"context": {
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.ModeController",
|
||||
"instance": "Washer.WashCycle",
|
||||
"name": "mode",
|
||||
"value": "WashCycle.Normal",
|
||||
"timeOfSample": "2017-02-03T16:20:00.00Z",
|
||||
"uncertaintyInMilliseconds": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
31
test/fixtures/alexa-docs/alexa-modecontroller/StateReport.json
vendored
Normal file
31
test/fixtures/alexa-docs/alexa-modecontroller/StateReport.json
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "StateReport",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token that matches the request",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {}
|
||||
},
|
||||
"context": {
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.ModeController",
|
||||
"instance": "Washer.WashCycle",
|
||||
"name": "mode",
|
||||
"value": "WashCycle.Delicates",
|
||||
"timeOfSample": "2017-02-03T16:20:00.00Z",
|
||||
"uncertaintyInMilliseconds": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
6
test/fixtures/alexa-docs/alexa-modecontroller/mode.property.json
vendored
Normal file
6
test/fixtures/alexa-docs/alexa-modecontroller/mode.property.json
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"namespace": "Alexa.ModeController",
|
||||
"name": "mode",
|
||||
"instance": "Washer.WashTemperature",
|
||||
"value": "WashTemperature.Cold"
|
||||
}
|
||||
24
test/fixtures/alexa-docs/alexa-rangecontroller/AdjustRangeValue.directive.json
vendored
Normal file
24
test/fixtures/alexa-docs/alexa-rangecontroller/AdjustRangeValue.directive.json
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"directive": {
|
||||
"header": {
|
||||
"namespace": "Alexa.RangeController",
|
||||
"instance": "Fan.Speed",
|
||||
"name": "AdjustRangeValue",
|
||||
"messageId": "Unique version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID",
|
||||
"cookie": {}
|
||||
},
|
||||
"payload": {
|
||||
"rangeValueDelta": -5,
|
||||
"rangeValueDeltaDefault": false
|
||||
}
|
||||
}
|
||||
}
|
||||
31
test/fixtures/alexa-docs/alexa-rangecontroller/AdjustRangeValue.response.json
vendored
Normal file
31
test/fixtures/alexa-docs/alexa-rangecontroller/AdjustRangeValue.response.json
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "Response",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token that matches the request",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {}
|
||||
},
|
||||
"context": {
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.RangeController",
|
||||
"instance": "Fan.Speed",
|
||||
"name": "rangeValue",
|
||||
"value": 10,
|
||||
"timeOfSample": "2017-02-03T16:20:50.52Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
50
test/fixtures/alexa-docs/alexa-rangecontroller/ChangeReport.json
vendored
Normal file
50
test/fixtures/alexa-docs/alexa-rangecontroller/ChangeReport.json
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "ChangeReport",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {
|
||||
"change": {
|
||||
"cause": {
|
||||
"type": "PHYSICAL_INTERACTION"
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.RangeController",
|
||||
"instance": "Fan.Speed",
|
||||
"name": "rangeValue",
|
||||
"value": 0,
|
||||
"timeOfSample": "2017-02-03T16:20:50.52Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
},
|
||||
{
|
||||
"namespace": "Alexa.PowerController",
|
||||
"name": "powerState",
|
||||
"value": "OFF",
|
||||
"timeOfSample": "2017-02-03T16:20:50.52Z",
|
||||
"uncertaintyInMilliseconds": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"namespace": "Alexa.EndpointHealth",
|
||||
"name": "connectivity",
|
||||
"value": {
|
||||
"value": "OK"
|
||||
},
|
||||
"timeOfSample": "2017-02-03T16:20:00.00Z",
|
||||
"uncertaintyInMilliseconds": 60000
|
||||
}
|
||||
}
|
||||
23
test/fixtures/alexa-docs/alexa-rangecontroller/SetRangeValue.directive.json
vendored
Normal file
23
test/fixtures/alexa-docs/alexa-rangecontroller/SetRangeValue.directive.json
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"directive": {
|
||||
"header": {
|
||||
"namespace": "Alexa.RangeController",
|
||||
"instance": "Fan.Speed",
|
||||
"name": "SetRangeValue",
|
||||
"messageId": "Unique version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID",
|
||||
"cookie": {}
|
||||
},
|
||||
"payload": {
|
||||
"rangeValue": 7
|
||||
}
|
||||
}
|
||||
}
|
||||
31
test/fixtures/alexa-docs/alexa-rangecontroller/SetRangeValue.response.json
vendored
Normal file
31
test/fixtures/alexa-docs/alexa-rangecontroller/SetRangeValue.response.json
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "Response",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token that matches the request",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {}
|
||||
},
|
||||
"context": {
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.RangeController",
|
||||
"instance": "Fan.Speed",
|
||||
"name": "rangeValue",
|
||||
"value": 7,
|
||||
"timeOfSample": "2017-02-03T16:20:50.52Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
38
test/fixtures/alexa-docs/alexa-rangecontroller/StateReport.json
vendored
Normal file
38
test/fixtures/alexa-docs/alexa-rangecontroller/StateReport.json
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "StateReport",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token that matches the request",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {}
|
||||
},
|
||||
"context": {
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.RangeController",
|
||||
"instance": "Fan.Speed",
|
||||
"name": "rangeValue",
|
||||
"value": 4,
|
||||
"timeOfSample": "2017-02-03T16:21:00.00Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
},
|
||||
{
|
||||
"namespace": "Alexa.PowerController",
|
||||
"name": "powerState",
|
||||
"value": "ON",
|
||||
"timeOfSample": "2017-02-03T16:20:00.00Z",
|
||||
"uncertaintyInMilliseconds": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
6
test/fixtures/alexa-docs/alexa-rangecontroller/rangeValue.property.json
vendored
Normal file
6
test/fixtures/alexa-docs/alexa-rangecontroller/rangeValue.property.json
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"namespace": "Alexa.RangeController",
|
||||
"instance": "Fan.Speed",
|
||||
"name": "rangeValue",
|
||||
"value": 10
|
||||
}
|
||||
51
test/fixtures/alexa-docs/alexa-togglecontroller/ChangeReport.json
vendored
Normal file
51
test/fixtures/alexa-docs/alexa-togglecontroller/ChangeReport.json
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "ChangeReport",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {
|
||||
"change": {
|
||||
"cause": {
|
||||
"type": "PHYSICAL_INTERACTION"
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.ToggleController",
|
||||
"instance": "Oven.OvenLight",
|
||||
"name": "toggleState",
|
||||
"value": "OFF",
|
||||
"timeOfSample": "2017-02-04T16:20:50.52Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
},
|
||||
{
|
||||
"namespace": "Alexa.ToggleController",
|
||||
"instance": "Stovetop.ResidualHeat",
|
||||
"name": "toggleState",
|
||||
"value": "ON",
|
||||
"timeOfSample": "2017-02-04T16:20:50.42Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"namespace": "Alexa.EndpointHealth",
|
||||
"name": "connectivity",
|
||||
"value": {
|
||||
"value": "OK"
|
||||
},
|
||||
"timeOfSample": "2017-02-04T16:00:00.00Z",
|
||||
"uncertaintyInMilliseconds": 0
|
||||
}
|
||||
}
|
||||
39
test/fixtures/alexa-docs/alexa-togglecontroller/StateReport.json
vendored
Normal file
39
test/fixtures/alexa-docs/alexa-togglecontroller/StateReport.json
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "StateReport",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token that matches the request",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {}
|
||||
},
|
||||
"context": {
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.ToggleController",
|
||||
"instance": "Stovetop.ResidualHeat",
|
||||
"name": "toggleState",
|
||||
"value": "OFF",
|
||||
"timeOfSample": "2017-02-03T16:20:50.52Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
},
|
||||
{
|
||||
"namespace": "Alexa.ToggleController",
|
||||
"instance": "Oven.Light",
|
||||
"name": "toggleState",
|
||||
"value": "ON",
|
||||
"timeOfSample": "2017-02-04T08:00:00.10Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
21
test/fixtures/alexa-docs/alexa-togglecontroller/TurnOff.directive.json
vendored
Normal file
21
test/fixtures/alexa-docs/alexa-togglecontroller/TurnOff.directive.json
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"directive": {
|
||||
"header": {
|
||||
"namespace": "Alexa.ToggleController",
|
||||
"instance": "Oven.Light",
|
||||
"name": "TurnOff",
|
||||
"messageId": "Unique version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID",
|
||||
"cookie": {}
|
||||
},
|
||||
"payload": {}
|
||||
}
|
||||
}
|
||||
31
test/fixtures/alexa-docs/alexa-togglecontroller/TurnOff.response.json
vendored
Normal file
31
test/fixtures/alexa-docs/alexa-togglecontroller/TurnOff.response.json
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "Response",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token that matches the request",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {}
|
||||
},
|
||||
"context": {
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.ToggleController",
|
||||
"instance": "Oven.Light",
|
||||
"name": "toggleState",
|
||||
"value": "OFF",
|
||||
"timeOfSample": "2017-02-03T16:20:50.52Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
21
test/fixtures/alexa-docs/alexa-togglecontroller/TurnOn.directive.json
vendored
Normal file
21
test/fixtures/alexa-docs/alexa-togglecontroller/TurnOn.directive.json
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"directive": {
|
||||
"header": {
|
||||
"namespace": "Alexa.ToggleController",
|
||||
"instance": "Oven.Light",
|
||||
"name": "TurnOn",
|
||||
"messageId": "Unique version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID",
|
||||
"cookie": {}
|
||||
},
|
||||
"payload": {}
|
||||
}
|
||||
}
|
||||
31
test/fixtures/alexa-docs/alexa-togglecontroller/TurnOn.response.json
vendored
Normal file
31
test/fixtures/alexa-docs/alexa-togglecontroller/TurnOn.response.json
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa",
|
||||
"name": "Response",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID",
|
||||
"correlationToken": "Opaque correlation token that matches the request",
|
||||
"payloadVersion": "3"
|
||||
},
|
||||
"endpoint": {
|
||||
"scope": {
|
||||
"type": "BearerToken",
|
||||
"token": "OAuth2.0 bearer token"
|
||||
},
|
||||
"endpointId": "Endpoint ID"
|
||||
},
|
||||
"payload": {}
|
||||
},
|
||||
"context": {
|
||||
"properties": [
|
||||
{
|
||||
"namespace": "Alexa.ToggleController",
|
||||
"instance": "Oven.Light",
|
||||
"name": "toggleState",
|
||||
"value": "ON",
|
||||
"timeOfSample": "2017-02-03T16:20:50.52Z",
|
||||
"uncertaintyInMilliseconds": 500
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
127
test/fixtures/alexa-docs/alexa-togglecontroller/discovery-oven.json
vendored
Normal file
127
test/fixtures/alexa-docs/alexa-togglecontroller/discovery-oven.json
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa.Discovery",
|
||||
"name": "Discover.Response",
|
||||
"payloadVersion": "3",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID"
|
||||
},
|
||||
"payload": {
|
||||
"endpoints": [
|
||||
{
|
||||
"endpointId": "Unique ID of the endpoint",
|
||||
"manufacturerName": "Kitchen Appliance Plus",
|
||||
"description": "Smart Oven by Kitchen Appliance Plus",
|
||||
"friendlyName": "Oven",
|
||||
"displayCategories": [
|
||||
"OVEN"
|
||||
],
|
||||
"cookie": {},
|
||||
"capabilities": [
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa.ToggleController",
|
||||
"instance": "Oven.OvenLight",
|
||||
"version": "3",
|
||||
"properties": {
|
||||
"supported": [
|
||||
{
|
||||
"name": "toggleState"
|
||||
}
|
||||
],
|
||||
"proactivelyReported": true,
|
||||
"retrievable": true,
|
||||
"nonControllable": false
|
||||
},
|
||||
"capabilityResources": {
|
||||
"friendlyNames": [
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Oven light",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Luz del horno",
|
||||
"locale": "es-MX"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Lumière du four",
|
||||
"locale": "fr-CA"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa.ToggleController",
|
||||
"instance": "Stovetop.ResidualHeat",
|
||||
"version": "3",
|
||||
"properties": {
|
||||
"supported": [
|
||||
{
|
||||
"name": "toggleState"
|
||||
}
|
||||
],
|
||||
"proactivelyReported": true,
|
||||
"retrievable": true,
|
||||
"nonControllable": true
|
||||
},
|
||||
"capabilityResources": {
|
||||
"friendlyNames": [
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Stovetop is still hot",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Todavía está caliente",
|
||||
"locale": "es-MX"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Encore chaude",
|
||||
"locale": "fr-CA"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa.EndpointHealth",
|
||||
"version": "3",
|
||||
"properties": {
|
||||
"supported": [
|
||||
{
|
||||
"name": "connectivity"
|
||||
}
|
||||
],
|
||||
"proactivelyReported": true,
|
||||
"retrievable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa",
|
||||
"version": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
247
test/fixtures/alexa-docs/alexa-togglecontroller/discovery-range-and-toggle.json
vendored
Normal file
247
test/fixtures/alexa-docs/alexa-togglecontroller/discovery-range-and-toggle.json
vendored
Normal file
|
|
@ -0,0 +1,247 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa.Discovery",
|
||||
"name": "Discover.Response",
|
||||
"payloadVersion": "3",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID"
|
||||
},
|
||||
"payload": {
|
||||
"endpoints": [
|
||||
{
|
||||
"endpointId": "Unique ID of the endpoint",
|
||||
"friendlyName": "Tower Fan",
|
||||
"description": "Tower Fan by Sample Manufacturer",
|
||||
"manufacturerName": "Sample Manufacturer",
|
||||
"displayCategories": [
|
||||
"FAN"
|
||||
],
|
||||
"cookie": {},
|
||||
"capabilities": [
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa.ToggleController",
|
||||
"version": "3",
|
||||
"instance": "SampleManufacturer.Fan.Oscillate",
|
||||
"capabilityResources": {
|
||||
"friendlyNames": [
|
||||
{
|
||||
"@type": "asset",
|
||||
"value": {
|
||||
"assetId": "Alexa.Setting.Oscillate"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Rotate",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Rotation",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Girar",
|
||||
"locale": "es-MX"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Rotation",
|
||||
"locale": "fr-CA"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"properties": {
|
||||
"proactivelyReported": true,
|
||||
"retrievable": true,
|
||||
"supported": [
|
||||
{
|
||||
"name": "toggleState"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa.RangeController",
|
||||
"version": "3",
|
||||
"instance": "SampleManufacturer.Fan.Speed",
|
||||
"capabilityResources": {
|
||||
"friendlyNames": [
|
||||
{
|
||||
"@type": "asset",
|
||||
"value": {
|
||||
"assetId": "Alexa.Setting.FanSpeed"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Speed",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Velocidad",
|
||||
"locale": "es-MX"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Vitesse",
|
||||
"locale": "fr-CA"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"properties": {
|
||||
"supported": [
|
||||
{
|
||||
"name": "rangeValue"
|
||||
}
|
||||
],
|
||||
"proactivelyReported": true,
|
||||
"retrievable": true
|
||||
},
|
||||
"configuration": {
|
||||
"supportedRange": {
|
||||
"minimumValue": 1,
|
||||
"maximumValue": 10,
|
||||
"precision": 1
|
||||
},
|
||||
"presets": [
|
||||
{
|
||||
"rangeValue": 10,
|
||||
"presetResources": {
|
||||
"friendlyNames": [
|
||||
{
|
||||
"@type": "asset",
|
||||
"value": {
|
||||
"assetId": "Alexa.Value.Maximum"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "asset",
|
||||
"value": {
|
||||
"assetId": "Alexa.Value.High"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Highest",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Fast",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Alta",
|
||||
"locale": "es-MX"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Élevée",
|
||||
"locale": "fr-CA"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"rangeValue": 1,
|
||||
"presetResources": {
|
||||
"friendlyNames": [
|
||||
{
|
||||
"@type": "asset",
|
||||
"value": {
|
||||
"assetId": "Alexa.Value.Minimum"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "asset",
|
||||
"value": {
|
||||
"assetId": "Alexa.Value.Low"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Lowest",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Slow",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Baja",
|
||||
"locale": "es-MX"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Faible",
|
||||
"locale": "fr-CA"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa.PowerController",
|
||||
"version": "3",
|
||||
"properties": {
|
||||
"supported": [
|
||||
{
|
||||
"name": "powerState"
|
||||
}
|
||||
],
|
||||
"proactivelyReported": true,
|
||||
"retrievable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa",
|
||||
"version": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
111
test/fixtures/alexa-docs/alexa-togglecontroller/discovery-semantics.json
vendored
Normal file
111
test/fixtures/alexa-docs/alexa-togglecontroller/discovery-semantics.json
vendored
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
{
|
||||
"event": {
|
||||
"header": {
|
||||
"namespace": "Alexa.Discovery",
|
||||
"name": "Discover.Response",
|
||||
"payloadVersion": "3",
|
||||
"messageId": "Unique identifier, preferably a version 4 UUID"
|
||||
},
|
||||
"payload": {
|
||||
"endpoints": [
|
||||
{
|
||||
"endpointId": "Unique ID of the endpoint",
|
||||
"manufacturerName": "manufacturer name",
|
||||
"description": "Smart Garbage Can by Manufacturer",
|
||||
"friendlyName": "garbage can",
|
||||
"displayCategories": [
|
||||
"OTHER"
|
||||
],
|
||||
"cookie": {},
|
||||
"capabilities": [
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa.ToggleController",
|
||||
"instance": "GarbageCan.Lid",
|
||||
"version": "3",
|
||||
"properties": {
|
||||
"supported": [
|
||||
{
|
||||
"name": "toggleState"
|
||||
}
|
||||
],
|
||||
"proactivelyReported": true,
|
||||
"retrievable": true
|
||||
},
|
||||
"capabilityResources": {
|
||||
"friendlyNames": [
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Garbage can lid",
|
||||
"locale": "en-US"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Tapa del bote de basura",
|
||||
"locale": "es-MX"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "text",
|
||||
"value": {
|
||||
"text": "Couvercle de poubelle",
|
||||
"locale": "fr-CA"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"semantics": {
|
||||
"actionMappings": [
|
||||
{
|
||||
"@type": "ActionsToDirective",
|
||||
"actions": [
|
||||
"Alexa.Actions.Close"
|
||||
],
|
||||
"directive": {
|
||||
"name": "TurnOff",
|
||||
"payload": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type": "ActionsToDirective",
|
||||
"actions": [
|
||||
"Alexa.Actions.Open"
|
||||
],
|
||||
"directive": {
|
||||
"name": "TurnOn",
|
||||
"payload": {}
|
||||
}
|
||||
}
|
||||
],
|
||||
"stateMappings": [
|
||||
{
|
||||
"@type": "StatesToValue",
|
||||
"states": [
|
||||
"Alexa.States.Closed"
|
||||
],
|
||||
"value": "OFF"
|
||||
},
|
||||
{
|
||||
"@type": "StatesToValue",
|
||||
"states": [
|
||||
"Alexa.States.Open"
|
||||
],
|
||||
"value": "ON"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "AlexaInterface",
|
||||
"interface": "Alexa",
|
||||
"version": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
6
test/fixtures/alexa-docs/alexa-togglecontroller/toggleState.property.json
vendored
Normal file
6
test/fixtures/alexa-docs/alexa-togglecontroller/toggleState.property.json
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"namespace": "Alexa.ToggleController",
|
||||
"instance": "Oven.OvenLight",
|
||||
"name": "toggleState",
|
||||
"value": "ON"
|
||||
}
|
||||
97
test/fixtures/interfaces.js
vendored
97
test/fixtures/interfaces.js
vendored
|
|
@ -1,20 +1,101 @@
|
|||
"use strict";
|
||||
// One entry per interface that is described in full: the page its examples were saved from (test/helpers/fixtures.js)
|
||||
// and declarations that give capability objects of those examples.
|
||||
// and declarations that give capability objects of Amazon's discovery examples.
|
||||
//
|
||||
// namespace the interface
|
||||
// page the page of the interface; test/fixtures/alexa-docs/<page>/ has its examples
|
||||
// declared [{ options, as: [example, n] }]: device.add(descriptor, options) gives the n-th capability object of
|
||||
// the interface in that discovery example (n counts from 0 and defaults to it)
|
||||
// declared [{ options, example, page, n }]: device.add(descriptor, options) gives the n-th capability object of
|
||||
// the interface in that discovery example. n counts from 0 and defaults to it, page defaults to the
|
||||
// page of the interface. The pages of RangeController and ModeController fold their discovery
|
||||
// examples away, so they were not saved: the range is taken from an example of the ToggleController
|
||||
// page, and ModeController has none.
|
||||
//
|
||||
// test/registry/descriptors.test.js and test/device/discovery.test.js run the entries. The first one fails for a
|
||||
// descriptor of tier 1 or 2 that has no entry.
|
||||
const { asset, semantics, text } = require("alex2node");
|
||||
|
||||
const reported = { retrievable: true, proactivelyReported: true };
|
||||
const inThreeLanguages = (english, spanish, french) => [text(english, "en-US"), text(spanish, "es-MX"), text(french, "fr-CA")];
|
||||
|
||||
module.exports = [
|
||||
{ namespace: "Alexa", page: "alexa-interface", declared: [{ options: {}, as: ["discovery"] }] },
|
||||
{ namespace: "Alexa.BrightnessController", page: "alexa-brightnesscontroller", declared: [{ options: reported, as: ["discovery"] }] },
|
||||
{ namespace: "Alexa.EndpointHealth", page: "alexa-endpointhealth", declared: [{ options: reported, as: ["discovery"] }] },
|
||||
{ namespace: "Alexa.PowerController", page: "alexa-powercontroller", declared: [{ options: reported, as: ["discovery"] }] },
|
||||
{ namespace: "Alexa.TemperatureSensor", page: "alexa-temperaturesensor", declared: [{ options: reported, as: ["discovery"] }] },
|
||||
{ namespace: "Alexa", page: "alexa-interface", declared: [{ options: {}, example: "discovery" }] },
|
||||
{ namespace: "Alexa.BrightnessController", page: "alexa-brightnesscontroller", declared: [{ options: reported, example: "discovery" }] },
|
||||
{ namespace: "Alexa.EndpointHealth", page: "alexa-endpointhealth", declared: [{ options: reported, example: "discovery" }] },
|
||||
{ namespace: "Alexa.ModeController", page: "alexa-modecontroller", declared: [] },
|
||||
{ namespace: "Alexa.PowerController", page: "alexa-powercontroller", declared: [{ options: reported, example: "discovery" }] },
|
||||
{
|
||||
namespace: "Alexa.RangeController",
|
||||
page: "alexa-rangecontroller",
|
||||
declared: [{
|
||||
page: "alexa-togglecontroller",
|
||||
example: "discovery-range-and-toggle",
|
||||
options: {
|
||||
...reported,
|
||||
instance: "SampleManufacturer.Fan.Speed",
|
||||
friendlyNames: [asset("Alexa.Setting.FanSpeed"), ...inThreeLanguages("Speed", "Velocidad", "Vitesse")],
|
||||
range: { min: 1, max: 10, precision: 1 },
|
||||
presets: [
|
||||
{
|
||||
value: 10,
|
||||
friendlyNames: [
|
||||
asset("Alexa.Value.Maximum"), asset("Alexa.Value.High"), text("Highest"), text("Fast"), text("Alta", "es-MX"),
|
||||
text("Élevée", "fr-CA"),
|
||||
],
|
||||
},
|
||||
{
|
||||
value: 1,
|
||||
friendlyNames: [
|
||||
asset("Alexa.Value.Minimum"), asset("Alexa.Value.Low"), text("Lowest"), text("Slow"), text("Baja", "es-MX"),
|
||||
text("Faible", "fr-CA"),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
}],
|
||||
},
|
||||
{ namespace: "Alexa.TemperatureSensor", page: "alexa-temperaturesensor", declared: [{ options: reported, example: "discovery" }] },
|
||||
{
|
||||
namespace: "Alexa.ToggleController",
|
||||
page: "alexa-togglecontroller",
|
||||
declared: [
|
||||
{
|
||||
example: "discovery-oven",
|
||||
options: {
|
||||
...reported,
|
||||
nonControllable: false,
|
||||
instance: "Oven.OvenLight",
|
||||
friendlyNames: inThreeLanguages("Oven light", "Luz del horno", "Lumière du four"),
|
||||
},
|
||||
},
|
||||
{
|
||||
example: "discovery-oven",
|
||||
n: 1,
|
||||
options: {
|
||||
...reported,
|
||||
nonControllable: true,
|
||||
instance: "Stovetop.ResidualHeat",
|
||||
friendlyNames: inThreeLanguages("Stovetop is still hot", "Todavía está caliente", "Encore chaude"),
|
||||
},
|
||||
},
|
||||
{
|
||||
example: "discovery-semantics",
|
||||
options: {
|
||||
...reported,
|
||||
instance: "GarbageCan.Lid",
|
||||
friendlyNames: inThreeLanguages("Garbage can lid", "Tapa del bote de basura", "Couvercle de poubelle"),
|
||||
semantics: semantics().action("Close", "TurnOff", {}).action("Open", "TurnOn", {}).state("Closed", "OFF").state("Open", "ON"),
|
||||
},
|
||||
},
|
||||
{
|
||||
example: "discovery-range-and-toggle",
|
||||
options: {
|
||||
...reported,
|
||||
instance: "SampleManufacturer.Fan.Oscillate",
|
||||
friendlyNames: [
|
||||
asset("Alexa.Setting.Oscillate"), text("Rotate"), text("Rotation"), text("Girar", "es-MX"), text("Rotation", "fr-CA"),
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
|
|||
44
test/fixtures/types.ts
vendored
44
test/fixtures/types.ts
vendored
|
|
@ -3,7 +3,7 @@
|
|||
// declaration stops rejecting what follows it.
|
||||
import {
|
||||
ActionMapping, AlexaActions, AlexaInterfaceType, Assets, BrightnessController, DeclarationError, DisplayCategory, EndpointHealth,
|
||||
PowerController, PowerState, TemperatureSensor, asset, registry, text,
|
||||
ModeController, PowerController, PowerState, RangeController, TemperatureSensor, ToggleController, asset, registry, semantics, text,
|
||||
} from "alex2node";
|
||||
import type {
|
||||
Alex2MQTT, Alex2MQTTOptions, AlexaInterface, AlexaStatusMessage, AssetId, Capability, CapabilityJson, ChangeCause, Device,
|
||||
|
|
@ -74,6 +74,44 @@ const names: Label[] = [asset("Alexa.Setting.Opening"), text("Position"), text("
|
|||
// @ts-expect-error not in the global Alexa catalog
|
||||
asset("Alexa.Setting.Openning");
|
||||
|
||||
// The generic controllers: an instance name, friendly names and the options of the interface
|
||||
const lift = blinds.add(RangeController, {
|
||||
instance: "Blind.Lift",
|
||||
friendlyNames: names,
|
||||
range: { min: 0, max: 100, precision: 1 },
|
||||
unit: "Alexa.Unit.Percent",
|
||||
presets: [{ value: 100, friendlyNames: [asset("Alexa.Value.Maximum")] }],
|
||||
semantics: semantics()
|
||||
.action("Close", "SetRangeValue", { rangeValue: 0 })
|
||||
.action(["Open", AlexaActions.Raise], "SetRangeValue", { rangeValue: 100 })
|
||||
.state("Closed", 0)
|
||||
.stateRange("Open", 1, 100),
|
||||
retrievable: true,
|
||||
proactivelyReported: true,
|
||||
});
|
||||
blinds.add(ModeController, {
|
||||
instance: "Blind.Position",
|
||||
friendlyNames: [text("Position")],
|
||||
supportedModes: [{ value: "Position.Up", friendlyNames: [asset("Alexa.Value.Open")] }, { value: "Position.Down", friendlyNames: [asset("Alexa.Value.Close")] }],
|
||||
ordered: false,
|
||||
});
|
||||
blinds.add(ToggleController, { instance: "Blind.Tilt", friendlyNames: [text("Tilt")], nonControllable: true });
|
||||
// @ts-expect-error a range controller has a range
|
||||
blinds.add(RangeController, { instance: "Blind.Tilt", friendlyNames: [text("Tilt")] });
|
||||
// @ts-expect-error a generic controller has an instance name and friendly names
|
||||
blinds.add(ToggleController, { proactivelyReported: true });
|
||||
// @ts-expect-error and so it cannot be declared without options
|
||||
blinds.add(ToggleController);
|
||||
// @ts-expect-error not a unit of measure
|
||||
blinds.add(RangeController, { instance: "Blind.Tilt", friendlyNames: [text("Tilt")], range: { min: 0, max: 90, precision: 1 }, unit: "Alexa.Unit.Percentage" });
|
||||
// @ts-expect-error not a phrase Alexa has
|
||||
semantics().action("Shut", "TurnOff");
|
||||
// What a directive carries and what a property holds are typed by the descriptor
|
||||
const lower: Infer<typeof RangeController.directives.AdjustRangeValue.payload> = { rangeValueDelta: -10, rangeValueDeltaDefault: false };
|
||||
const position: Schema<number> = lift.descriptor.properties.rangeValue.value;
|
||||
// @ts-expect-error a mode is a string, or null when none is set
|
||||
const current: Infer<typeof ModeController.properties.mode.value> = 3;
|
||||
|
||||
// The registry: a descriptor by its namespace or by the 1.x enum member
|
||||
const described: InterfaceDescriptor = registry.get("Alexa.PowerController");
|
||||
const version: string = registry.get(AlexaInterfaceType.ENDPOINT_HEALTH).version;
|
||||
|
|
@ -95,6 +133,6 @@ const measured: Infer<typeof temperature> = { value: 20, scale: "CELSIUS" };
|
|||
const rankine: Infer<typeof temperature> = { value: 20, scale: "RANKINE" };
|
||||
|
||||
export {
|
||||
options, added, chained, sent, on, namespace, reachable, announced, endpoint, problems, names, version, refused, opening,
|
||||
percent, vacuum, misspelt, notAUnit, measured, rankine,
|
||||
options, added, chained, sent, on, namespace, reachable, announced, endpoint, problems, names, lower, position, current, version,
|
||||
refused, opening, percent, vacuum, misspelt, notAUnit, measured, rankine,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -30,16 +30,20 @@ test("a descriptor of tier 1 or 2 has an entry in test/fixtures/interfaces.js, a
|
|||
assert.deepEqual(described.map((descriptor) => descriptor.namespace), interfaces.map((entry) => entry.namespace).sort());
|
||||
});
|
||||
|
||||
for (const { namespace, page } of interfaces) {
|
||||
for (const { namespace, page, declared } of interfaces) {
|
||||
test(`${namespace}: version, properties, directive payloads and property values of ${page}.html`, () => {
|
||||
const descriptor = registry.get(namespace);
|
||||
assert.ok(descriptor.doc.endsWith(`/${page}.html`), descriptor.doc);
|
||||
|
||||
for (const name of examples(page).filter((example) => example.startsWith("discovery"))) {
|
||||
for (const capability of capabilities(page, namespace, name)) {
|
||||
assert.equal(capability.version, descriptor.version, `${name}: version`);
|
||||
// The discovery examples of the page, and of another page when the entry declares from one
|
||||
const discovery = examples(page).filter((example) => example.startsWith("discovery")).map((example) => [page, example]);
|
||||
for (const { page: other = page, example } of declared) discovery.push([other, example]);
|
||||
for (const [from, example] of discovery) {
|
||||
for (const capability of capabilities(from, namespace, example)) {
|
||||
assert.equal(capability.version, descriptor.version, `${example}: version`);
|
||||
assert.equal("instance" in capability, descriptor.instanced, `${example}: instance`);
|
||||
const supported = capability.properties ? capability.properties.supported.map((property) => property.name) : [];
|
||||
for (const property of supported) assert.ok(property in descriptor.properties, `${name}: ${property}`);
|
||||
assert.deepEqual(supported, Object.keys(descriptor.properties), `${example}: properties`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +68,19 @@ for (const { namespace, page } of interfaces) {
|
|||
});
|
||||
}
|
||||
|
||||
test("the error types of an interface are in the error type table under its error namespace", () => {
|
||||
const { ERROR_TYPES } = require("../../dist/cjs/registry/catalog.js");
|
||||
const withErrors = registry.list().filter((descriptor) => descriptor.errorNamespace || descriptor.errorTypes);
|
||||
// The generic controllers answer a safety problem under Alexa.Safety
|
||||
for (const name of ["Alexa.ModeController", "Alexa.RangeController", "Alexa.ToggleController"]) {
|
||||
assert.deepEqual(registry.get(name).errorTypes, ["OBSTACLE_DETECTED", "SAFETY_BEAM_BREACHED"], name);
|
||||
}
|
||||
for (const { namespace, errorNamespace, errorTypes } of withErrors) {
|
||||
assert.ok(errorTypes.length > 0, namespace);
|
||||
for (const type of errorTypes) assert.equal(ERROR_TYPES[type], errorNamespace, `${namespace}: ${type}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("Alexa.EndpointHealth is version 3.1 and reports connectivity, with a reason when it has one", () => {
|
||||
const { version, properties } = registry.get("Alexa.EndpointHealth");
|
||||
assert.equal(version, "3.1");
|
||||
|
|
|
|||
104
test/registry/semantics.test.js
Normal file
104
test/registry/semantics.test.js
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
"use strict";
|
||||
// semantics(): the mappings of phrases to directives and of states to values, as discovery lists them.
|
||||
const { test } = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const { Actions, AlexaActions, ModeController, RangeController, SchemaError, States, ToggleController, semantics } = require("alex2node");
|
||||
const { doc } = require("../helpers/fixtures.js");
|
||||
|
||||
// The schema of the semantics option of an interface, and the message of the SchemaError it throws.
|
||||
const semanticsOf = (descriptor) => ({
|
||||
parse: (input) => descriptor.options.parse({ ...COMPLETE[descriptor.namespace], semantics: input }).semantics,
|
||||
});
|
||||
const COMPLETE = {
|
||||
"Alexa.RangeController": { range: { min: 0, max: 100, precision: 1 } },
|
||||
"Alexa.ModeController": {
|
||||
supportedModes: ["Up", "Down"].map((name) => ({ value: `Position.${name}`, friendlyNames: [{ "@type": "text", value: { text: name, locale: "en-US" } }] })),
|
||||
},
|
||||
"Alexa.ToggleController": {},
|
||||
};
|
||||
function refusal(descriptor, input) {
|
||||
try {
|
||||
semanticsOf(descriptor).parse(input);
|
||||
} catch (err) {
|
||||
assert.ok(err instanceof SchemaError, `threw ${err}`);
|
||||
return err.message;
|
||||
}
|
||||
return assert.fail("the semantics were accepted");
|
||||
}
|
||||
|
||||
test("semantics() builds the Semantics object of alexa-discovery-objects.html", () => {
|
||||
const built = semantics()
|
||||
.action(["Close", "Lower"], "SetRangeValue", { rangeValue: 0 })
|
||||
.action(["Open", "Raise"], "SetRangeValue", { rangeValue: 100 })
|
||||
.state("Closed", 0)
|
||||
.stateRange("Open", 1, 100);
|
||||
const { semantics: example } = doc("alexa-discovery-objects", "semantics");
|
||||
assert.deepEqual(semanticsOf(RangeController).parse(built), example);
|
||||
assert.deepEqual(built.actionMappings[0], doc("alexa-discovery-objects", "actionMapping"));
|
||||
assert.deepEqual(built.stateMappings[1], doc("alexa-discovery-objects", "stateMapping"));
|
||||
// What the schema returns is the plain object, and it takes that object as it takes the builder
|
||||
assert.equal(Object.getPrototypeOf(semanticsOf(RangeController).parse(built)), Object.prototype);
|
||||
assert.deepEqual(semanticsOf(RangeController).parse(example), example);
|
||||
});
|
||||
|
||||
test("a phrase and a state are given by name, by id or by the AlexaActions enum of 1.x", () => {
|
||||
const { actionMappings, stateMappings } = semantics()
|
||||
.action("Open", "TurnOn")
|
||||
.action("Alexa.Actions.Close", "TurnOff")
|
||||
.action([AlexaActions.Raise, Actions[3]], "TurnOn")
|
||||
.state(["Closed", States[0]], "OFF");
|
||||
assert.deepEqual(actionMappings.map((mapping) => mapping.actions), [
|
||||
["Alexa.Actions.Open"], ["Alexa.Actions.Close"], ["Alexa.Actions.Raise", "Alexa.Actions.Lower"],
|
||||
]);
|
||||
assert.deepEqual(stateMappings[0].states, ["Alexa.States.Closed", "Alexa.States.Open"]);
|
||||
// No payload given, none in discovery; an empty one is kept, as in the ToggleController examples
|
||||
assert.deepEqual(actionMappings[0].directive, { name: "TurnOn" });
|
||||
assert.deepEqual(semantics().action("Open", "TurnOn", {}).actionMappings[0].directive, { name: "TurnOn", payload: {} });
|
||||
assert.deepEqual(semanticsOf(ToggleController).parse(semantics().action("Open", "TurnOn")).actionMappings[0].directive, { name: "TurnOn" });
|
||||
});
|
||||
|
||||
test("a mapping is checked against the directives and the property of the interface", () => {
|
||||
const cases = [
|
||||
[RangeController, semantics().action("Open", "SetRange", { rangeValue: 100 }),
|
||||
'semantics.actionMappings[0].directive.name: expected a directive of the interface: SetRangeValue, AdjustRangeValue, got "SetRange"'],
|
||||
[RangeController, semantics().action("Open", "SetRangeValue", { rangeValue: "100" }),
|
||||
'semantics.actionMappings[0].directive.payload.rangeValue: expected a number, got "100"'],
|
||||
[RangeController, semantics().action("Open", "SetRangeValue"),
|
||||
"semantics.actionMappings[0].directive.payload.rangeValue: expected a number, got nothing"],
|
||||
[RangeController, semantics().action("Lower", "AdjustRangeValue", { rangeValueDelta: -10 }),
|
||||
"semantics.actionMappings[0].directive.payload.rangeValueDeltaDefault: expected true or false, got nothing"],
|
||||
[RangeController, semantics().action("Shut", "SetRangeValue", { rangeValue: 0 }),
|
||||
'semantics.actionMappings[0].actions[0]: expected a phrase of Alexa.Actions: Open, Close, Raise, Lower, got "Alexa.Actions.Shut"'],
|
||||
[RangeController, semantics().state("Ajar", 50),
|
||||
'semantics.stateMappings[0].states[0]: expected a state of Alexa.States: Open, Closed, Low, Empty, Full, Done, Stuck, got "Alexa.States.Ajar"'],
|
||||
[RangeController, semantics().state("Closed", "OFF"), 'semantics.stateMappings[0].value: expected a number, got "OFF"'],
|
||||
[RangeController, semantics().stateRange("Open", 100, 1), "semantics.stateMappings[0].range: the minimumValue 100 is above the maximumValue 1"],
|
||||
[ToggleController, semantics().state("Open", "on"), 'semantics.stateMappings[0].value: expected ON | OFF, got "on"'],
|
||||
[ToggleController, semantics().stateRange("Open", 1, 100), 'semantics.stateMappings[0].@type: expected StatesToValue, got "StatesToRange"'],
|
||||
[ModeController, semantics().state("Closed", 0), "semantics.stateMappings[0].value: expected a string of 1 or more characters, got 0"],
|
||||
[ToggleController, semantics(), "semantics: expected semantics() with at least one action or state, got {}"],
|
||||
[ToggleController, "open", 'semantics: expected semantics() with at least one action or state, got "open"'],
|
||||
[ToggleController, { actionMappings: [{ "@type": "ActionToDirective", actions: ["Alexa.Actions.Open"], directive: { name: "TurnOn" } }] },
|
||||
'semantics.actionMappings[0].@type: expected "ActionsToDirective", got "ActionToDirective"'],
|
||||
];
|
||||
for (const [descriptor, input, message] of cases) assert.equal(refusal(descriptor, input), message);
|
||||
});
|
||||
|
||||
test("the phrases and states of Alexa hunches are for a ToggleController", () => {
|
||||
const eco = semantics().action("SetEcoOn", "TurnOn").action("SetEcoOff", "TurnOff").state("EcoOn", "ON").state("EcoOff", "OFF");
|
||||
assert.deepEqual(semanticsOf(ToggleController).parse(eco), {
|
||||
actionMappings: [
|
||||
{ "@type": "ActionsToDirective", actions: ["Alexa.Actions.SetEcoOn"], directive: { name: "TurnOn" } },
|
||||
{ "@type": "ActionsToDirective", actions: ["Alexa.Actions.SetEcoOff"], directive: { name: "TurnOff" } },
|
||||
],
|
||||
stateMappings: [
|
||||
{ "@type": "StatesToValue", states: ["Alexa.States.EcoOn"], value: "ON" },
|
||||
{ "@type": "StatesToValue", states: ["Alexa.States.EcoOff"], value: "OFF" },
|
||||
],
|
||||
});
|
||||
assert.match(
|
||||
refusal(RangeController, semantics().action("SetEcoOn", "SetRangeValue", { rangeValue: 20 })),
|
||||
/^semantics\.actionMappings\[0\]\.actions\[0\]: expected a phrase of Alexa\.Actions: Open, Close, Raise, Lower, got "Alexa\.Actions\.SetEcoOn"$/
|
||||
);
|
||||
assert.match(refusal(ModeController, semantics().state("EcoOn", "Position.Up")), /expected a state of Alexa\.States: Open, Closed, Low, Empty, Full, Done, Stuck, got/);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue