cap:smoke-detection
- detect smoke¶
This capability is used to mark sensors that monitor an environment for smoke.
if(thing.matches('cap:smoke-detection')) {
console.log('Detected smoke:', await thing.smokeDetected());
thing.on('smoke', () => console.log('Smoke has been detected'));
thing.on('smokeDetected', () => console.log('Smoke is no longer detected'));
}
API¶
-
smokeDetected
()¶ Get if smoke is being detected.
Returns: Promise that resolves to a boolean indicating if smoke is currently being detected. Example:
// Using async/await const smokePresent = await thing.smokeDetected(); // Using promise then/catch thing.smokeDetected() .then(smokePresent => ...) .catch(...);
Events¶
-
smokeDetectedChanged
The current smoke detection status has changed.
thing.on('smokeDetectedChanged', value => console.log('Detection changed to:', value));
-
smoke
Emitted when smoke has been detected and
smokeDetected()
changes totrue
.thing.on('smoke', () => console.log('Smoke detected'));
-
smokeCleared
Emitted when smoke is no longer detected and
smokeDetected
changes tofalse
.thing.on('smokeCleared', () => console.log('Smoke no longer detected'));
Protected methods¶
-
updateSmokeDetected
(value[, autoIdleTimeout])¶ Update the current smoke detected status.
Arguments: - value (boolean) – The smoke detected status,
true
if smoke detected otherwisefalse
. - autoIdleTimeout (duration) – Optional duration to switch back the smoke detection status to
false
.
Example:
this.updateSmokeDetected(false); this.updateSmokeDetected(true, '20s');
- value (boolean) – The smoke detected status,
Implementing capability¶
Implementors of this capability should call updateSmokeDetected
when
smoke is detected. Implementations may choose between using automatic timeouts
for switching smoke detected status back to false
or managing the switching
on their own.
const { Sensor, SmokeDetection } = require('abstract-things/sensors');
class Example extends Sensor.with(SmokeDetection) {
constructor() {
super();
this.updateSmokeDetected(true, '1m');
}
}