cap:cleaning-state - get if cleaning

cleaning-state is used when a thing can report if is currently cleaning. This is commonly used for things that also support autonomous cleaning. Things implementing This capability also support error states.

if(thing.matches('cap:cleaning-state')) {
        console.log('Currently cleaning:', await thing.cleaning());
}

API

Events

cleaningChanged

The cleaning state has changed. Payload will be the new state as a boolean.

Example:

thing.on('cleaningChanged', c => ...);
cleaningStarted

Cleaning has started.

Example:

thing.on('cleaningStarted', () => console.log('Doing some cleaning'));
cleaningDone

Cleaning was completed without any errors.

thing.on('cleaningDone', () => console.log('Cleaning is now done'));
cleaningError

Cleaning has encountered an error.

thing.on('cleaningError', () => console.log('Cleaning encountered an error'));
cleaningStopped

Cleaning has stopped (for any reason).

thing.on('cleaningStopped', () => console.log('No longer doing any cleaning'));

Protected methods

updateCleaning(cleaning)

Update wether the thing is performing cleaning or not.

Arguments:
  • cleaning (boolean) – Boolean indicating if cleaning is currently being performed.

Example:

// Currently doing some cleaning
this.updateCleaning(true);

Implementing capability

When implementing this capability take care to call updateCleaning whenever cleaning is being done and also when cleaning stops. For errors calling updateError(error) will automatically set cleaning to false.

const { Thing } = require('abstract-things');
const { CleaningState } = require('abstract-things/climate');

class Example extends Thing.with(CleaningState) {

}