cap:target-humidity
- read the target humidity¶
The target-humidity
capability is used by things such as
humidifers and dehumidifiers that
support stopping when a certain target humidity is reached. Some things may
also support setting the target humidity via
adjustable-target-humidity.
if(thing.matches('cap:target-humidity')) {
const humidity = await thing.targetHumidity();
console.log('Target humidity:', humidity);
}
API¶
-
targetHumidity
()¶ Get the current target humidity.
Returns: Promise that resolves to the current target humidity as a percentage. Example:
const target = await thing.targetHumidity();
Events¶
-
targetHumidityChanged
The current target humidity has changed. Payload will be the new target humidity as a percentage.
Example:
thing.on('targetHumidityChanged', th => console.log('Target:', th));
Protected methods¶
-
updateTargetHumidity
(target)¶ Update the current target humidity.
Arguments: - target (percentage) – The new target humidity as a percentage.
Example:
this.updateTargetHumidity(40); this.updateTargetHumidity('55%');
Implementing capability¶
When implementing this capability the implementor needs to call
updateTargetHumidity
whenever a change in target humidity is detected.
const { Thing } = require('abstract-things');
const { TargetHumidity } = require('abstract-things/climate');
class Example extends Thing.with(TargetHumidity) {
}