1.5.2: send() never rejects (status, error, scene, change report: resolves the topic or "" and reports the failure through the bridge's error event when listened to - 1.5.1 rejected, and an un-caught .send() killed the host on any broker hiccup); types ship (declaration: true, dist/*.d.ts tracked; addSupportedModes takes {value, modeResources}, ActionMapping payload optional, addHealthProp accepts EndpointHealth or the string); disconnect()/connect() re-binds devices to the new client; registerDevice returns the existing device on a duplicate endpointId (warning via the log hook, console.warn without one); ThermostatController discovery lists targetSetpoint and drops adaptiveRecoveryStatus; the UNSUPORTED INTERFACE TYPE stderr spam goes through the log hook. Examples: require("alex2node"), an error listener in each, EndpointHealth.OK, neutral endpoint ids, BlindControl reads correlationToken from the header, the thermostat reports Fahrenheit as Fahrenheit, ExamplePowerController is power-only again + new ExamplePowerControllerWithBrightness. readme (install from Forgejo, 1.5.2 changelog, table syntax), LICENSE (MIT); tests for the non-rejecting send, reconnect, duplicate, thermostat discovery and the shipped declaration signatures (8/8 on an in-process broker).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
717af632de
commit
275f00f8a7
35 changed files with 1011 additions and 176 deletions
|
|
@ -1,20 +1,23 @@
|
|||
// Import the library ("alex2node" is the installed package; inside this checkout it resolves to the built dist/ via package.json "exports")
|
||||
const {
|
||||
Alex2MQTT,
|
||||
AlexaInterfaceType,
|
||||
PowerController,
|
||||
} = require("../dist/index.js");
|
||||
|
||||
EndpointHealth,
|
||||
} = require("alex2node");
|
||||
|
||||
require("dotenv").config();
|
||||
|
||||
|
||||
const username = process.env.MQTT_USERNAME;
|
||||
const password = process.env.MQTT_PASSWORD;
|
||||
const rootTopic = process.env.MQTT_ROOT_TOPIC;
|
||||
|
||||
const alex2NodeClient = new Alex2MQTT(username, password, rootTopic, true);
|
||||
|
||||
const alex2NodeClient = new Alex2MQTT(username, password, rootTopic, false); // set the 4th argument to true to print every MQTT payload
|
||||
alex2NodeClient.connect();
|
||||
|
||||
alex2NodeClient.on("error", (e) => console.error("broker:", e.message)); // Log broker errors (on 1.5.0 this listener is also what keeps an outage from killing the process)
|
||||
|
||||
const deviceName = "Custom Device";
|
||||
const customToggle = alex2NodeClient.registerDevice(deviceName, "endpoint8");
|
||||
const customToggle = alex2NodeClient.registerDevice(deviceName, "custom-device-1");
|
||||
|
||||
// Define 8 toggle instances and friendly names
|
||||
const switchCount = 8;
|
||||
|
|
@ -40,7 +43,7 @@ const {
|
|||
const { correlationToken } = payload.header;
|
||||
const status = customToggle.getStatusMessage(correlationToken);
|
||||
|
||||
status.addHealthProp("OK");
|
||||
status.addHealthProp(EndpointHealth.OK);
|
||||
|
||||
// Report all toggle states
|
||||
for (let i = 0; i < switchCount; i++) {
|
||||
|
|
@ -68,7 +71,7 @@ const {
|
|||
|
||||
const status = customToggle.getStatusMessage(correlationToken, true);
|
||||
status
|
||||
.addHealthProp("OK")
|
||||
.addHealthProp(EndpointHealth.OK)
|
||||
.addToggleControllerProp(toggleStates[index], instance)
|
||||
.send();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue