cap:contact
- contact sensing¶
This capability is used to mark sensors that report a wether contact is detected, such as for door and window sensors that detect if the door or window is open.
if(thing.matches('cap:contact')) {
console.log('Has contact:', await thing.contact());
}
API¶
-
contact
()¶ Boolean representing if the sensor is currently detecting contact.
Returns: Promise that resolves to if the sensor is detecting contact. Example:
if(await thing.contact()) { console.log('Thing has detected contact'); }
Events¶
-
contactChanged
¶ The contact value has changed. Payload is the new contact state as a boolean.
Example:
thing.on('contactChanged', v => console.log('Contact is now:', c));
-
opened
¶ The sensor has detected it is does not have contact and is now opened.
Example:
thing.on('opened', v => console.log('Sensor is now open'));
Protected methods¶
Implementing capability¶
Implementors of this capability should call updateContact
whenever the
contact state changes.
const { Sensor, Contact } = require('abstract-things/sensors');
class Example extends Sensor.with(Contact) {
constructor() {
super();
this.updateContact(true);
}
}