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