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
|
|
@ -65,6 +65,8 @@ export class AlexaStatusMessage {
|
|||
private endpointId: string;
|
||||
private mqttClient: MqttClient;
|
||||
private isDeferred: boolean;
|
||||
/** Where a failed publish is reported (set by the Device that built this message, 1.5.2): send() never rejects. */
|
||||
public onPublishError?: (err: Error) => void;
|
||||
|
||||
constructor(
|
||||
correlationToken: string,
|
||||
|
|
@ -202,7 +204,8 @@ export class AlexaStatusMessage {
|
|||
);
|
||||
}
|
||||
|
||||
public addHealthProp(health: EndpointHealth, uncertaintyInMs = 0): this {
|
||||
/** Alexa.EndpointHealth connectivity: EndpointHealth.OK / UNREACHABLE (the plain strings "OK" / "UNREACHABLE" are accepted too). */
|
||||
public addHealthProp(health: EndpointHealth | `${EndpointHealth}`, uncertaintyInMs = 0): this {
|
||||
return this.addProperty(
|
||||
AlexaInterfaceType.ENDPOINT_HEALTH,
|
||||
"connectivity",
|
||||
|
|
@ -289,15 +292,20 @@ export class AlexaStatusMessage {
|
|||
/**
|
||||
* Publish: a Response/StateReport to <root>/<endpoint>/alexaResponce (sendAsync: deferredResponse), a ChangeReport
|
||||
* to <root>/changeReport (Alex2MQTT adds the user's token and posts it to the Alexa event gateway). Resolves with
|
||||
* the topic; rejects on a publish error (1.4.0 only logged).
|
||||
* the topic, or "" when the publish failed - the error then goes to the bridge's "error" event (when listened to).
|
||||
* Never rejects (1.5.1 did, so an un-caught send() could kill the host).
|
||||
*/
|
||||
public send(sendAsync: boolean = false): Promise<string> {
|
||||
const payloadStr = JSON.stringify(this.toJSON());
|
||||
const topic = this.changeCause
|
||||
? `${this.rootTopic}/changeReport`
|
||||
: `${this.rootTopic}/${this.endpointId}/${sendAsync ? "deferredResponse" : "alexaResponce"}`; //Yes this should be response but it is incorrect in both Alex2MQTT and Alex2ESP so for consistency is is wrong here too
|
||||
return new Promise((resolve, reject) => {
|
||||
this.mqttClient.publish(topic, payloadStr, (err) => (err ? reject(err) : resolve(topic)));
|
||||
return new Promise((resolve) => {
|
||||
this.mqttClient.publish(topic, payloadStr, (err) => {
|
||||
if (!err) return resolve(topic);
|
||||
if (this.onPublishError) this.onPublishError(err); // -> the bridge's "error" event (when somebody listens)
|
||||
resolve(""); // 1.5.1 rejected here, and an un-caught send() then killed the host on any broker hiccup
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue