cap:mode
- monitor mode¶
mode
is used for things that have a mode that can be monitored.
if(thing.matches('cap:mode')) {
console.log('Mode is', await thing.mode());
thing.on('modeChanged', mode => console.log('Mode is now', mode));
}
API¶
Events¶
-
modeChanged
The current mode has changed. Payload of the event is the current mode as a string.
thing.on('modeChanged', mode => console.log('Mode is now', mode));
-
modesChanged
The available modes have changed.
Protected methods¶
-
updateMode
(mode)¶ Update the currently detected mode. Calling this method with a new mode will change the mode and trigger the
mode
event.Arguments: - mode (string) – The id of the current mode.
Example:
this.updateMode('silent');
-
updateModes
(modes)¶ Update the modes that are available for the thing.
Arguments: - modes (array) – Array of modes as codes. Entries in the array will be automatically converted to codes if possible.
Example:
this.updateModes([ 'idle', 'silent: Silent speed', { id: 'auto', description: 'Autoselect speed' } ]);
Implementing capability¶
When implementing this capability call updateModes
in the constructor or
initCallback
of the thing. updateMode
should be used whenever the mode
is changed.
Example:
const { Thing, Mode } = require('abstract-things');
class Example exends Thing.with(Mode) {
initCallback() {
return super.initCallback()
.then(() => this.updateModes(modesDetected));
}
}