diff --git a/README.md b/README.md index ae15f62..aaccfeb 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ const thing = new Thing(partialTD); ### Properties -Set property handlers: +Set property read and write handlers for each property defined in the Thing Description: ```javascript thing.setPropertyReadHandler('on', async function () { @@ -97,21 +97,27 @@ thing.setPropertyReadHandler('level', async function () { }); thing.setPropertyWriteHandler('on', async function (value) { - // Update the lamp state. + // Update the lamp on/off state. +}); + +thing.setPropertyWriteHandler('level', async function (value) { + // Update the lamp level. }); ``` -Property changes are emitted automatically when an observable property is written via its write handler, but for other property changes you should explicitly call `emitPropertyChange()` to notify active SSE observers. You can provide the new value directly, or -omit it to read the current value using the property's read handler: +Property changes are emitted automatically when an observable property is written via its write handler, but for other property changes you should explicitly call `emitPropertyChange()` to notify active SSE observers: ```javascript await thing.emitPropertyChange('on', true); + +If the value argument is omitted then the current value is read using the read handler and that value is emitted. + await thing.emitPropertyChange('on'); ``` ### Actions -Set action handlers: +Set action invoke handlers for each action defined in the Thing Description: ```javascript thing.setActionInvokeHandler('fade', async (input, signal) => { @@ -123,12 +129,18 @@ For synchronous actions set `synchronous` to `true` in the Thing Description. Th For asynchronous actions set `synchronous` to `false` in the Thing Description. The invoke handler should accept the action input as its first argument, and an optional `AbortSignal` as a second argument so the action can be stopped if the request is cancelled. -### Thing Server +### Events -Expose to the Thing to the Web of Things by starting its web server, providing -a port number as an argument: +Call `emitEvent()` whenever an event occurs for one of the +event affordances defined in the Thing Description: + +```javascript +thing.emitEvent('overheated', 90); +``` + +### Thing Server -Create and start a Thing server using your Thing. +Expose to the Thing to the Web of Things by instantiating a Thing server for the Thing, then calling start() to start its web server (providing a port number as an argument): ```javascript const server = new ThingServer(thing); diff --git a/src/action-affordance.js b/src/action-affordance.js index 4246026..fd7d3df 100644 --- a/src/action-affordance.js +++ b/src/action-affordance.js @@ -62,7 +62,7 @@ class ActionAffordance extends InteractionAffordance { outputSchema; /** - * Create a new Action. + * Create a new Action Affordance. * * @param {string} name The name of the ActionAffordance from its * key in an actions Map. @@ -409,7 +409,7 @@ class ActionAffordance extends InteractionAffordance { /** @type {Array