1.5.0: brightness + mode props in the power example (as published to npm)

This commit is contained in:
David 2026-09-22 00:18:22 +00:00
parent f09d03636d
commit f4300688f8
2 changed files with 9 additions and 3 deletions

View file

@ -23,7 +23,7 @@ alex2NodeClient.connect(); // Connect to the MQTT broker
const deviceName = "Bedroom Light";
// Register the device with a unique endpoint ID (you can use something like "endpoint1")
const bedroomLight = alex2NodeClient.registerDevice(deviceName, "endpoint2");
const bedroomLight = alex2NodeClient.registerDevice(deviceName, "2E3AE9");
// Add the PowerController capability (for turning on/off the device)
bedroomLight.addCapability(AlexaInterfaceType.POWER_CONTROLLER);
@ -31,6 +31,9 @@ bedroomLight.addCapability(AlexaInterfaceType.POWER_CONTROLLER);
// Log the device name to verify registration
console.log(bedroomLight.getName());
const momentaryModeInstance = "mode.signal.beep";
const defaultMomentaryMode = "mode.signal.beep.Normal";
/**
* Handle Alexa's ReportState directive.
* This occurs when Alexa queries the current state of the device (e.g., during routines or device status checks).
@ -44,7 +47,9 @@ bedroomLight.on("ReportState", (payload) => {
status
.addHealthProp("OK") // Device is healthy
.addPowerControllerProp(outputState); // Report the current power state (ON/OFF)
.addPowerControllerProp(outputState) // Report the current power state (ON/OFF)
.addBrightnessControllerProp(100)
.addModeControllerProp(momentaryModeInstance, defaultMomentaryMode);
status.send(); // Send the state report back to Alexa
});
@ -75,6 +80,7 @@ bedroomLight.on("Event", (directive, interfaceType) => {
status
.addHealthProp("OK")
.addPowerControllerProp(outputState)
.addBrightnessControllerProp(100)
.send();
}
});

View file

@ -1,6 +1,6 @@
{
"name": "alex2node",
"version": "1.4.0",
"version": "1.5.0",
"description": "A Node.js library for creating Alexa-compatible devices using MQTT, based on Alex2MQTT.",
"main": "dist/index.js",
"types": "dist/index.d.ts",