examples: one runnable file per recipe on the 2.0 API, the 1.x files in examples/legacy

Ten recipes: lamp, colour lamp, thermostat, blind, lock (deferred), contact
sensor (ChangeReport), scene, doorbell (raise), typed errors, and a plug as an
ES module. Each reads ALEX2MQTT_USERNAME, _PASSWORD and _ROOT_TOPIC and names
the ones that are missing. The nine examples of 1.5.2 move to examples/legacy
unchanged.

test/examples.test.js starts every file with node, its broker connection sent
to a broker on 127.0.0.1 (test/helpers/loopback.js), discovers the device,
sends directives and checks the answers. A legacy file is started and its
discovery compared with the answer the 1.5.2 build gave, recorded in
test/fixtures/legacy-examples.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
David 2026-09-28 21:38:07 +00:00
parent 2cbcde563e
commit 8379a65d78
25 changed files with 1705 additions and 0 deletions

View file

@ -0,0 +1,770 @@
{
"BlindControl.js": [
{
"endpointId": "bedroom-blinds-1",
"friendlyName": "Bedroom Blinds",
"description": "Alexa to Node.js bridge",
"manufacturerName": "Alex2Node",
"displayCategories": [
"LIGHT"
],
"additionalAttributes": {
"manufacturer": "Alex2Node",
"model": "Alex2Node_v1.0.0",
"serialNumber": "Alex2Node",
"firmwareVersion": "1.0.0",
"softwareVersion": "1.0.0",
"customIdentifier": "Alex2Node"
},
"capabilities": [
{
"interface": "Alexa.PowerController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "powerState"
}
]
}
},
{
"interface": "Alexa.ToggleController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "toggleState"
}
]
},
"instance": "NodeJS.Toggle",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Bedroom Blinds",
"locale": "en-US"
}
}
]
},
"semantics": {
"actionMappings": [
{
"@type": "ActionsToDirective",
"actions": [
"Alexa.Actions.Close"
],
"directive": {
"name": "TurnOn"
}
},
{
"@type": "ActionsToDirective",
"actions": [
"Alexa.Actions.Open"
],
"directive": {
"name": "TurnOff"
}
}
]
}
}
]
}
],
"ExampleModeController.js": [
{
"endpointId": "fan-1",
"friendlyName": "Test mode controller",
"description": "Alexa to Node.js bridge",
"manufacturerName": "Alex2Node",
"displayCategories": [
"OTHER"
],
"additionalAttributes": {
"manufacturer": "Alex2Node",
"model": "Alex2Node_v1.0.0",
"serialNumber": "Alex2Node",
"firmwareVersion": "1.0.0",
"softwareVersion": "1.0.0",
"customIdentifier": "Alex2Node"
},
"capabilities": [
{
"interface": "Alexa.ModeController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "mode"
}
]
},
"configuration": {
"ordered": true,
"supportedModes": [
{
"value": "mode.fanmode.Normal",
"modeResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Normal",
"locale": "en-US"
}
}
]
}
},
{
"value": "mode.fanmode.Low",
"modeResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Low",
"locale": "en-US"
}
}
]
}
}
]
},
"instance": "mode.fanmode",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Fan Mode",
"locale": "en-US"
}
}
]
}
}
]
}
],
"ExamplePowerController.js": [
{
"endpointId": "bedroom-light-1",
"friendlyName": "Bedroom Light",
"description": "Alexa to Node.js bridge",
"manufacturerName": "Alex2Node",
"displayCategories": [
"LIGHT"
],
"additionalAttributes": {
"manufacturer": "Alex2Node",
"model": "Alex2Node_v1.0.0",
"serialNumber": "Alex2Node",
"firmwareVersion": "1.0.0",
"softwareVersion": "1.0.0",
"customIdentifier": "Alex2Node"
},
"capabilities": [
{
"interface": "Alexa.PowerController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "powerState"
}
]
}
}
]
}
],
"ExamplePowerControllerDeferred.js": [
{
"endpointId": "deferred-light-1",
"friendlyName": "Deferred Light",
"description": "Alexa to Node.js bridge",
"manufacturerName": "Alex2Node",
"displayCategories": [
"LIGHT"
],
"additionalAttributes": {
"manufacturer": "Alex2Node",
"model": "Alex2Node_v1.0.0",
"serialNumber": "Alex2Node",
"firmwareVersion": "1.0.0",
"softwareVersion": "1.0.0",
"customIdentifier": "Alex2Node"
},
"capabilities": [
{
"interface": "Alexa.PowerController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "powerState"
}
]
}
}
]
}
],
"ExamplePowerControllerWithBrightness.js": [
{
"endpointId": "living-room-light-1",
"friendlyName": "Living Room Light",
"description": "Alexa to Node.js bridge",
"manufacturerName": "Alex2Node",
"displayCategories": [
"LIGHT"
],
"additionalAttributes": {
"manufacturer": "Alex2Node",
"model": "Alex2Node_v1.0.0",
"serialNumber": "Alex2Node",
"firmwareVersion": "1.0.0",
"softwareVersion": "1.0.0",
"customIdentifier": "Alex2Node"
},
"capabilities": [
{
"interface": "Alexa.PowerController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "powerState"
}
]
}
},
{
"interface": "Alexa.BrightnessController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "brightness"
}
]
}
}
]
}
],
"ExamplePowerControllerWithErrors.js": [
{
"endpointId": "bad-light-1",
"friendlyName": "bad light",
"description": "Alexa to Node.js bridge",
"manufacturerName": "Alex2Node",
"displayCategories": [
"LIGHT"
],
"additionalAttributes": {
"manufacturer": "Alex2Node",
"model": "Alex2Node_v1.0.0",
"serialNumber": "Alex2Node",
"firmwareVersion": "1.0.0",
"softwareVersion": "1.0.0",
"customIdentifier": "Alex2Node"
},
"capabilities": [
{
"interface": "Alexa.PowerController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "powerState"
}
]
}
}
]
}
],
"ExamplePowerControllerWithMomentary.js": [
{
"endpointId": "kitchen-light-1",
"friendlyName": "Kitchen Light",
"description": "Alexa to Node.js bridge",
"manufacturerName": "Alex2Node",
"displayCategories": [
"LIGHT"
],
"additionalAttributes": {
"manufacturer": "Alex2Node",
"model": "Alex2Node_v1.0.0",
"serialNumber": "Alex2Node",
"firmwareVersion": "1.0.0",
"softwareVersion": "1.0.0",
"customIdentifier": "Alex2Node"
},
"capabilities": [
{
"interface": "Alexa.PowerController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "powerState"
}
]
}
},
{
"interface": "Alexa.ModeController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "mode"
}
]
},
"configuration": {
"ordered": true,
"supportedModes": [
{
"value": "mode.signal.beep.Normal",
"modeResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Normal",
"locale": "en-US"
}
}
]
}
},
{
"value": "mode.signal.beep.Beep",
"modeResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Beep",
"locale": "en-US"
}
}
]
}
}
]
},
"instance": "mode.signal.beep",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Signal",
"locale": "en-US"
}
}
]
}
}
]
}
],
"ExampleThermostat.js": [
{
"endpointId": "thermostat-1",
"friendlyName": "Thermostat Test",
"description": "Alexa to Node.js bridge",
"manufacturerName": "Alex2Node",
"displayCategories": [
"TEMPERATURE_SENSOR",
"THERMOSTAT",
"OTHER"
],
"additionalAttributes": {
"manufacturer": "Alex2Node",
"model": "Alex2Node_v1.0.0",
"serialNumber": "Alex2Node",
"firmwareVersion": "1.0.0",
"softwareVersion": "1.0.0",
"customIdentifier": "Alex2Node"
},
"capabilities": [
{
"interface": "Alexa.ThermostatController",
"version": "3.2",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "targetSetpoint"
},
{
"name": "lowerSetpoint"
},
{
"name": "upperSetpoint"
},
{
"name": "thermostatMode"
}
]
},
"configuration": {
"supportedModes": [
"HEAT",
"COOL",
"AUTO",
"OFF"
],
"supportsScheduling": false
}
},
{
"interface": "Alexa.TemperatureSensor",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "temperature"
}
]
}
},
{
"interface": "Alexa.ModeController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "mode"
}
]
},
"configuration": {
"ordered": true,
"supportedModes": [
{
"value": "mode.fanmode.Auto",
"modeResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Auto",
"locale": "en-US"
}
}
]
}
},
{
"value": "mode.fanmode.On",
"modeResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "On",
"locale": "en-US"
}
}
]
}
}
]
},
"instance": "mode.fanmode",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Fan",
"locale": "en-US"
}
}
]
}
}
]
}
],
"ExampleToggleController.js": [
{
"endpointId": "custom-device-1",
"friendlyName": "Custom Device",
"description": "Alexa to Node.js bridge",
"manufacturerName": "Alex2Node",
"displayCategories": [
"LIGHT"
],
"additionalAttributes": {
"manufacturer": "Alex2Node",
"model": "Alex2Node_v1.0.0",
"serialNumber": "Alex2Node",
"firmwareVersion": "1.0.0",
"softwareVersion": "1.0.0",
"customIdentifier": "Alex2Node"
},
"capabilities": [
{
"interface": "Alexa.ToggleController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "toggleState"
}
]
},
"instance": "nodejs.toggle.switch1",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Switch 1",
"locale": "en-US"
}
}
]
}
},
{
"interface": "Alexa.ToggleController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "toggleState"
}
]
},
"instance": "nodejs.toggle.switch2",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Switch 2",
"locale": "en-US"
}
}
]
}
},
{
"interface": "Alexa.ToggleController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "toggleState"
}
]
},
"instance": "nodejs.toggle.switch3",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Switch 3",
"locale": "en-US"
}
}
]
}
},
{
"interface": "Alexa.ToggleController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "toggleState"
}
]
},
"instance": "nodejs.toggle.switch4",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Switch 4",
"locale": "en-US"
}
}
]
}
},
{
"interface": "Alexa.ToggleController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "toggleState"
}
]
},
"instance": "nodejs.toggle.switch5",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Switch 5",
"locale": "en-US"
}
}
]
}
},
{
"interface": "Alexa.ToggleController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "toggleState"
}
]
},
"instance": "nodejs.toggle.switch6",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Switch 6",
"locale": "en-US"
}
}
]
}
},
{
"interface": "Alexa.ToggleController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "toggleState"
}
]
},
"instance": "nodejs.toggle.switch7",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Switch 7",
"locale": "en-US"
}
}
]
}
},
{
"interface": "Alexa.ToggleController",
"version": "3",
"type": "AlexaInterface",
"properties": {
"retrievable": true,
"proactivelyReported": false,
"supported": [
{
"name": "toggleState"
}
]
},
"instance": "nodejs.toggle.switch8",
"capabilityResources": {
"friendlyNames": [
{
"@type": "text",
"value": {
"text": "Switch 8",
"locale": "en-US"
}
}
]
}
}
]
}
]
}