diff --git a/sensors/index.js b/sensors/index.js index 0e6a6eb..a856a50 100644 --- a/sensors/index.js +++ b/sensors/index.js @@ -19,3 +19,4 @@ module.exports.Temperature = require('./temperature'); module.exports.SmokeDetection = require('./smoke-detection'); module.exports.Voltage = require('./voltage'); module.exports.WaterDetection = require('./water-detection'); +module.exports.WaterLevel = require('./water-level'); diff --git a/sensors/water-level.js b/sensors/water-level.js new file mode 100644 index 0000000..179ab72 --- /dev/null +++ b/sensors/water-level.js @@ -0,0 +1,46 @@ +'use strict'; + +const Thing = require('../thing'); +const Sensor = require('./sensor'); +const { percentage } = require('../values'); + +module.exports = Thing.mixin(Parent => class extends Parent.with(Sensor) { + static get capability() { + return 'water-level'; + } + + static availableAPI(builder) { + builder.event('waterLevelChanged') + .type('percentage') + .description('Current water level has changed') + .done(); + + builder.action('waterLevel') + .description('Get the current water level') + .getterForState('waterLevel') + .returns('percentage', 'Current water level') + .done(); + + builder.action('wl') + .description('Get the current water level') + .getterForState('waterLevel') + .returns('percentage', 'Current water level') + .done(); + } + + get sensorTypes() { + return [ ...super.sensorTypes, 'waterLevel' ]; + } + + waterLevel() { + return this.value('waterLevel'); + } + + wl() { + return this.value('waterLevel'); + } + + updateWaterLevel(value) { + this.updateValue('waterLevel', percentage(value)); + } +});