bridge: publish through a Publisher; devices no longer hold the broker client
src/transport.ts has the Publisher interface, MqttPublisher (the client the bridge has at the time) and MemoryPublisher (tests without a broker); src/topics.ts names the four topics the library publishes to. Device, AlexaStatusMessage, AlexaErrorResponse and sendSceneResponse shared three copies of the publish-and-report code: they now call one send() that resolves the topic or "" and never rejects. registerDevice() and addDevice() work before connect(); a send() without a connection resolves "" and the "error" event says to call connect(). unregisterDevice() and clearDevices() take the publisher from the device. Device.setMqttClient() is gone, the first constructor argument of Device is ignored, and the message classes take a Publisher where they took the client. Tests: 108 -> 113. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
46fa06728c
commit
6789a1a077
39 changed files with 839 additions and 246 deletions
5
dist/esm/Alex2Node.d.ts
vendored
5
dist/esm/Alex2Node.d.ts
vendored
|
|
@ -38,6 +38,7 @@ declare class Alex2MQTT extends EventEmitter {
|
|||
private rootTopic;
|
||||
private debugLogging;
|
||||
private client;
|
||||
private readonly publisher;
|
||||
private devices;
|
||||
private MqttHost;
|
||||
private options;
|
||||
|
|
@ -62,7 +63,8 @@ declare class Alex2MQTT extends EventEmitter {
|
|||
*
|
||||
* Throws a DeclarationError when Alexa would reject the endpoint (an endpointId with a slash, a name with
|
||||
* punctuation) or when the endpointId is registered already. Discovery lists Alexa.EndpointHealth for the device
|
||||
* unless endpointHealth is false.
|
||||
* unless endpointHealth is false. A device can be declared before connect(): what it sends before the bridge has
|
||||
* a connection is not published, and the "error" event says so.
|
||||
*/
|
||||
addDevice(definition: EndpointDefinition): Device;
|
||||
registerDevice(name: string, endpointId: string, displayCategory?: DisplayCategory | DisplayCategory[] | null): Device;
|
||||
|
|
@ -71,6 +73,7 @@ declare class Alex2MQTT extends EventEmitter {
|
|||
unregisterDevice(endpointId: string): boolean;
|
||||
/** Forget every device. */
|
||||
clearDevices(): void;
|
||||
private release;
|
||||
getDevices(): Device[];
|
||||
getDevice(endpointId: string): Device | undefined;
|
||||
getRootTopic(): string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue