cap:brightness - read brightness

Capability used when a light supports reading the brightness. Usually this is combined with dimmable for lights that can actually change their brightness.

if(thing.matches('cap:brightness')) {
        console.log(await thing.brightness());
}

API

brightness()

Get the brightness of the light.

Returns:Promise that resolves to a percentage between 0 and 100, representing the brightness.

Example:

console.log(await thing.brightness());

Events

brightnessChanged

Brightness has changed. The payload of the event will be the brightness as a percentage.

thing.on('brightnessChanged', bri => console.log('Brightness is now', bri));

Protected functions

updateBrightness(brightness)

Update the current brightness. Should be called whenever the brightness has been detected to have changed.

Arguments:
  • brightness (number) – The new brightness as a percentage.

Implementing capability

This capability has no functions that need to be implemented. Things using the capability should call updateBrightness whenever the brightness changes.

const { Light, Brightness } = require('abstract-things/lights');

class Example extends Light.with(Brightness) {

        initCallback() {
                return super.initCallback()
                        .then(() => this.updateBrightness(initialBrightnessHere));
        }

}