cap:autonomous-charging - request charging

The autonomous-charging capability is used for things that have a battery and can charge it on request. This is commonly things such as vacuum robots that can head to a charging station to recharge.

if(thing.matches('cap:autonomous-charging')) {
        thing.charge()
                .then(() => console.log('Charging has been requested'))
                .catch(...);
}

API

charge()

Request that the thing charges.

Returns:Promise that resolves to null

Example:

thing.charge()
        .then(...)
        .catch(...);

await thing.charge();

Protected methods

activateCharging()

Activate charging of the thing. Called by charge().

Returns:Promise that resolves when activation is performed.

Example:

activateCharging() {
        return activateChargingSomehow();
}

Implementing capability

When implementing this capability the implementor needs to implement the method activateCharging.

const { Thing, AutonomousCharging } = require('abstract-things');

class Example extends Thing.with(AutonomousCharging) {

        activateCharging() {
                // Create a promise that resolves when charging has been activated
                return activateChargingSomehow();
        }

}