Six descriptors written from their pages replace the last stubs of tiers 1 and 2. A scene answers Activate and Deactivate through ctx.respond() with ActivationStarted and DeactivationStarted, the time and the cause filled in. device.raise(descriptor, name, payload) publishes DoorbellPress and the Event of a button on <root>/event with the endpoint and a new messageId; it throws a MessageError for an interface or instance the device did not declare, an event that answers a directive, a payload that does not fit and a message over 16000 bytes. TurnOn of a device with WakeOnLANController is deferred without the warning. On the wire: a doorbell has no properties object and proactivelyReported on the capability; SimpleEventSource is version 1.0, InventoryLevelSensor and WakeOnLANController version 3 (1.5.2: 1). A scene declared without options is announced as before. Alex2MQTT has no topic yet for the WakeUp event. 24 examples of the six pages are saved as fixtures. 267 tests pass, 241 before. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
112 lines
5.3 KiB
TypeScript
112 lines
5.3 KiB
TypeScript
import type { ChangeCause, ChangeReportMessage, DeferredResponseMessage, ErrorResponseMessage, ProactiveEventMessage, Property, ResponseMessage, SceneEventMessage } from "./types.js";
|
|
/** A message that would be dropped on its way to Alexa, refused where it is built. */
|
|
export declare class MessageError extends Error {
|
|
readonly endpointId: string;
|
|
readonly problem: string;
|
|
constructor(endpointId: string, problem: string);
|
|
}
|
|
interface Envelope {
|
|
endpointId: string;
|
|
/** Default: a new version 4 UUID, which is what Alexa recommends (message-guide.html, "Header object"). */
|
|
messageId?: string;
|
|
}
|
|
interface Answer extends Envelope {
|
|
/** The correlationToken of the directive that is answered. */
|
|
correlationToken: string;
|
|
}
|
|
export interface ResponseFields extends Answer {
|
|
/** Default: "Response". */
|
|
name?: string;
|
|
/** Default: "Alexa". An interface with a response of its own names it: Alexa.SecurityPanelController, Arm.Response. */
|
|
namespace?: string;
|
|
payload?: Record<string, unknown>;
|
|
/** The state of the endpoint after the directive. */
|
|
context?: readonly Property[];
|
|
}
|
|
/**
|
|
* The answer to a directive (alexa-response.html, "Synchronous response"). An endpoint with nothing to report
|
|
* answers with an empty list of properties, not without a context (state-reporting-for-smart-home-addons.html,
|
|
* "Directive response example for a property that isn't retrievable").
|
|
*/
|
|
export declare function response(fields: ResponseFields): ResponseMessage;
|
|
/** The answer to ReportState: every retrievable property of the endpoint. */
|
|
export declare function stateReport(fields: Answer & {
|
|
context?: readonly Property[];
|
|
}): ResponseMessage;
|
|
/**
|
|
* "The directive arrived, the answer follows": no context, the state is in the Response that follows
|
|
* (alexa-response.html, "Deferred response example").
|
|
*/
|
|
export declare function deferredResponse(fields: Answer & {
|
|
estimatedDeferralInSeconds?: number;
|
|
}): DeferredResponseMessage;
|
|
export interface ErrorResponseFields extends Answer {
|
|
/** "ENDPOINT_UNREACHABLE" */
|
|
type: string;
|
|
/** For the log of the skill. */
|
|
message: string;
|
|
/** The fields a type adds to the payload: validRange, currentDeviceMode. */
|
|
extra?: Record<string, unknown>;
|
|
/** Default: the namespace the type is documented under, see errorNamespace(). */
|
|
namespace?: string;
|
|
}
|
|
/** The answer to a directive the endpoint could not follow (alexa-errorresponse.html). */
|
|
export declare function errorResponse(fields: ErrorResponseFields): ErrorResponseMessage;
|
|
export interface ChangeReportFields extends Envelope {
|
|
/** Default: "PHYSICAL_INTERACTION". */
|
|
cause?: ChangeCause;
|
|
/** The properties that changed, at least one. */
|
|
changed: readonly Property[];
|
|
/** The other properties of the endpoint, as they are now. */
|
|
context?: readonly Property[];
|
|
}
|
|
/** The same property of the same instance, whatever its value. */
|
|
export declare const sameProperty: (a: Property, b: Property) => boolean;
|
|
/**
|
|
* A change of state nobody asked for. The header has no correlationToken (message-guide.html, "Header object").
|
|
* A property that changed is left out of the context: it is reported in one of the two (same page, "Context
|
|
* object"). Throws MessageError when nothing changed: Alex2MQTT drops such a report without a word.
|
|
*/
|
|
export declare function changeReport(fields: ChangeReportFields): ChangeReportMessage;
|
|
export interface SceneEventFields extends Answer {
|
|
/** true: ActivationStarted. false: DeactivationStarted. */
|
|
activated: boolean;
|
|
/** Default: "VOICE_INTERACTION", a scene is started by a directive. */
|
|
cause?: ChangeCause;
|
|
/** When the scene started. Default: now. */
|
|
timestamp?: string | Date;
|
|
}
|
|
/** The answer to Activate and Deactivate of a scene (alexa-scenecontroller.html). */
|
|
export declare function sceneEvent(fields: SceneEventFields): SceneEventMessage;
|
|
export interface ProactiveEventFields extends Envelope {
|
|
/** "Alexa.DoorbellEventSource" */
|
|
namespace: string;
|
|
/** "DoorbellPress" */
|
|
name: string;
|
|
/** The instance of a generic interface that raises the event. */
|
|
instance?: string;
|
|
/** Default: "3". */
|
|
payloadVersion?: string;
|
|
payload: Record<string, unknown>;
|
|
}
|
|
/** An event a device raises by itself, of any interface. The header has no correlationToken: nobody asked. */
|
|
export declare function proactiveEvent(fields: ProactiveEventFields): ProactiveEventMessage;
|
|
export interface DoorbellPressFields extends Envelope {
|
|
/** Default: "PHYSICAL_INTERACTION", somebody pressed the button. */
|
|
cause?: ChangeCause;
|
|
/** When the button was pressed. Default: now. */
|
|
timestamp?: string | Date;
|
|
}
|
|
/** Somebody rang (alexa-doorbelleventsource.html). */
|
|
export declare function doorbellPress(fields: DoorbellPressFields): ProactiveEventMessage;
|
|
export interface SimpleEventFields extends Envelope {
|
|
/** The instance of Alexa.SimpleEventSource that raises the event. */
|
|
instance: string;
|
|
/** The id of the event as discovery listed it: "Button.SinglePush.1". */
|
|
id: string;
|
|
/** When the event happened. Default: now. */
|
|
timestamp?: string | Date;
|
|
}
|
|
/** An event of a button or a sensor that routines start on (alexa-simpleeventsource.html). */
|
|
export declare function simpleEvent(fields: SimpleEventFields): ProactiveEventMessage;
|
|
export {};
|