1.5.0: brightness + mode props in the power example (as published to npm)
This commit is contained in:
parent
f09d03636d
commit
7f1cfdbe9c
2 changed files with 9 additions and 3 deletions
|
|
@ -23,7 +23,7 @@ alex2NodeClient.connect(); // Connect to the MQTT broker
|
||||||
const deviceName = "Bedroom Light";
|
const deviceName = "Bedroom Light";
|
||||||
|
|
||||||
// Register the device with a unique endpoint ID (you can use something like "endpoint1")
|
// 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)
|
// Add the PowerController capability (for turning on/off the device)
|
||||||
bedroomLight.addCapability(AlexaInterfaceType.POWER_CONTROLLER);
|
bedroomLight.addCapability(AlexaInterfaceType.POWER_CONTROLLER);
|
||||||
|
|
@ -31,6 +31,9 @@ bedroomLight.addCapability(AlexaInterfaceType.POWER_CONTROLLER);
|
||||||
// Log the device name to verify registration
|
// Log the device name to verify registration
|
||||||
console.log(bedroomLight.getName());
|
console.log(bedroomLight.getName());
|
||||||
|
|
||||||
|
const momentaryModeInstance = "mode.signal.beep";
|
||||||
|
const defaultMomentaryMode = "mode.signal.beep.Normal";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Alexa's ReportState directive.
|
* Handle Alexa's ReportState directive.
|
||||||
* This occurs when Alexa queries the current state of the device (e.g., during routines or device status checks).
|
* 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
|
status
|
||||||
.addHealthProp("OK") // Device is healthy
|
.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
|
status.send(); // Send the state report back to Alexa
|
||||||
});
|
});
|
||||||
|
|
@ -75,6 +80,7 @@ bedroomLight.on("Event", (directive, interfaceType) => {
|
||||||
status
|
status
|
||||||
.addHealthProp("OK")
|
.addHealthProp("OK")
|
||||||
.addPowerControllerProp(outputState)
|
.addPowerControllerProp(outputState)
|
||||||
|
.addBrightnessControllerProp(100)
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "alex2node",
|
"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.",
|
"description": "A Node.js library for creating Alexa-compatible devices using MQTT, based on Alex2MQTT.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue