messages: DoorbellPress is sent with the empty context of its page
proactiveEvent() built every proactive event without a context, so doorbellPress() and
device.raise(DoorbellEventSource, "DoorbellPress") left out the "context": {} that the example of
alexa-doorbelleventsource.html has. The Event of Alexa.SimpleEventSource is printed without one, so
the event descriptor says which it is (emptyContext) and raise() passes it on to the builder.
A raised DoorbellPress is now { event, context: {} }, 13 bytes longer; the Event of a button is
unchanged. The tests compare the keys and the context of the built message with the fixture of the
page, for the builder, the descriptor and raise(). 267 tests pass.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
3a07c861b1
commit
4a3dd81bcf
20 changed files with 86 additions and 18 deletions
1
dist/esm/device/Device.js
vendored
1
dist/esm/device/Device.js
vendored
|
|
@ -146,6 +146,7 @@ class Device extends EventEmitter {
|
|||
instance,
|
||||
payloadVersion: event.payloadVersion ?? capability.descriptor.version,
|
||||
payload: checked,
|
||||
emptyContext: event.emptyContext,
|
||||
});
|
||||
const bytes = Buffer.byteLength(JSON.stringify(message));
|
||||
if (bytes > topics.EVENT_BYTES)
|
||||
|
|
|
|||
8
dist/esm/messages/build.d.ts
vendored
8
dist/esm/messages/build.d.ts
vendored
|
|
@ -88,8 +88,14 @@ export interface ProactiveEventFields extends Envelope {
|
|||
/** Default: "3". */
|
||||
payloadVersion?: string;
|
||||
payload: Record<string, unknown>;
|
||||
/** true: the message has "context": {}, as the page of the event prints it. Default: no context. */
|
||||
emptyContext?: boolean;
|
||||
}
|
||||
/** An event a device raises by itself, of any interface. The header has no correlationToken: nobody asked. */
|
||||
/**
|
||||
* An event a device raises by itself, of any interface. The header has no correlationToken: nobody asked. The
|
||||
* pages differ on the context, so the caller says which it is: DoorbellPress is printed with an empty one
|
||||
* (alexa-doorbelleventsource.html), the Event of Alexa.SimpleEventSource without.
|
||||
*/
|
||||
export declare function proactiveEvent(fields: ProactiveEventFields): ProactiveEventMessage;
|
||||
export interface DoorbellPressFields extends Envelope {
|
||||
/** Default: "PHYSICAL_INTERACTION", somebody pressed the button. */
|
||||
|
|
|
|||
11
dist/esm/messages/build.js
vendored
11
dist/esm/messages/build.js
vendored
|
|
@ -99,7 +99,11 @@ export function sceneEvent(fields) {
|
|||
context: {},
|
||||
};
|
||||
}
|
||||
/** An event a device raises by itself, of any interface. The header has no correlationToken: nobody asked. */
|
||||
/**
|
||||
* An event a device raises by itself, of any interface. The header has no correlationToken: nobody asked. The
|
||||
* pages differ on the context, so the caller says which it is: DoorbellPress is printed with an empty one
|
||||
* (alexa-doorbelleventsource.html), the Event of Alexa.SimpleEventSource without.
|
||||
*/
|
||||
export function proactiveEvent(fields) {
|
||||
const { namespace, name, instance, messageId, payloadVersion, payload } = fields;
|
||||
return {
|
||||
|
|
@ -108,13 +112,16 @@ export function proactiveEvent(fields) {
|
|||
endpoint: { endpointId: fields.endpointId },
|
||||
payload,
|
||||
},
|
||||
...(fields.emptyContext ? { context: {} } : {}),
|
||||
};
|
||||
}
|
||||
/** Somebody rang (alexa-doorbelleventsource.html). */
|
||||
export function doorbellPress(fields) {
|
||||
const { endpointId, messageId } = fields;
|
||||
const payload = { cause: { type: fields.cause ?? "PHYSICAL_INTERACTION" }, timestamp: isoTime(fields.timestamp) };
|
||||
return proactiveEvent({ endpointId, messageId, namespace: "Alexa.DoorbellEventSource", name: "DoorbellPress", payload });
|
||||
return proactiveEvent({
|
||||
endpointId, messageId, namespace: "Alexa.DoorbellEventSource", name: "DoorbellPress", payload, emptyContext: true,
|
||||
});
|
||||
}
|
||||
/** An event of a button or a sensor that routines start on (alexa-simpleeventsource.html). */
|
||||
export function simpleEvent(fields) {
|
||||
|
|
|
|||
2
dist/esm/messages/types.d.ts
vendored
2
dist/esm/messages/types.d.ts
vendored
|
|
@ -73,4 +73,6 @@ export interface SceneEventMessage {
|
|||
/** An event a device raises by itself: DoorbellPress, the Event of Alexa.SimpleEventSource. */
|
||||
export interface ProactiveEventMessage {
|
||||
event: Event;
|
||||
/** Only with an event whose page prints it: DoorbellPress has an empty one, the Event of a button has none. */
|
||||
context?: {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export const DoorbellEventSource = defineInterface({
|
|||
properties: {},
|
||||
directives: {},
|
||||
events: {
|
||||
DoorbellPress: { name: "DoorbellPress", payload: happened("PHYSICAL_INTERACTION"), topic: "proactive" },
|
||||
DoorbellPress: { name: "DoorbellPress", payload: happened("PHYSICAL_INTERACTION"), topic: "proactive", emptyContext: true },
|
||||
},
|
||||
// The capability is the announcement that the endpoint raises the event: proactivelyReported whatever was declared
|
||||
discovery: () => ({ properties: false, topLevel: { proactivelyReported: true } }),
|
||||
|
|
|
|||
2
dist/esm/registry/types.d.ts
vendored
2
dist/esm/registry/types.d.ts
vendored
|
|
@ -66,6 +66,8 @@ export interface EventDescriptor {
|
|||
payload: Schema<any>;
|
||||
/** response: the answer to a directive. proactive: sent without one. */
|
||||
topic: "response" | "proactive";
|
||||
/** A proactive event that the page prints with "context": {}, DoorbellPress. Default: sent without a context. */
|
||||
emptyContext?: boolean;
|
||||
}
|
||||
/** What an interface adds to the capability object in discovery, next to the fields every capability has. */
|
||||
export interface CapabilityExtras {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue