diff --git a/lib/devices/eyecare-lamp2.js b/lib/devices/eyecare-lamp2.js index 35250c7..a96583a 100644 --- a/lib/devices/eyecare-lamp2.js +++ b/lib/devices/eyecare-lamp2.js @@ -8,9 +8,10 @@ const { percentage } = require('abstract-things/values'); const MiioDimmable = require('./capabilities/dimmable'); const MiioPower = require('./capabilities/power'); +const Mode = require('./capabilities/mode'); module.exports = class EyecareLamp2 extends Light - .with(MiioPower, MiioDimmable, Children, MiioApi) + .with(MiioPower, MiioDimmable, Children, MiioApi, Mode) { constructor(options) { @@ -26,7 +27,7 @@ module.exports = class EyecareLamp2 extends Light mapper: parseInt }); - // Get if the + // Eye Fatigue Reminder this.defineProperty('notifystatus', { name: 'notifyStatus', mapper: v => v === 'on' @@ -38,7 +39,7 @@ module.exports = class EyecareLamp2 extends Light mapper: v => v === 'on' }); - // Brightness of the secondary light + // Contrast this.defineProperty('ambvalue', { name: 'ambientBrightness', mapper: parseInt @@ -65,15 +66,17 @@ module.exports = class EyecareLamp2 extends Light } }); - this.setModes([ 'study', 'reading', 'phone' ]); + this.updateModes([ 'study', 'reading', 'phone' ]); + // Touch any button for lowest brightness at night is this property enabled this.defineProperty('bls', { - name: 'bls', + name: 'nightLight', mapper: v => v === 'on' }); + // Delay Off this.defineProperty('dvalue', { - name: 'dvalue', + name: 'delayOffMinutes', mapper: parseInt }); @@ -88,6 +91,8 @@ module.exports = class EyecareLamp2 extends Light } changeBrightness(brightness) { + brightness = percentage(brightness, { min: 1, max: 100 }); + return this.call('set_bright', [ brightness ], { refresh: true }).then(MiioApi.checkOk); @@ -112,8 +117,8 @@ module.exports = class EyecareLamp2 extends Light /** * Set the current eyeCare mode - * - changeMode(mode) { + */ + setMode(mode) { switch (mode) { case 'study': @@ -132,20 +137,40 @@ module.exports = class EyecareLamp2 extends Light refresh: true }); } - */ + + setBls(enable){ + return this.call('enable_bl', [enable ? 'on' : 'off'], { + refresh: true + }); + } + + setDelayOffMinutes(minutes){ + return this.call('delay_off', [minutes], { + refresh: true + }); + } + + setNotifyStatus(enable){ + return this.call('set_notifyuser', [enable ? 'on' : 'off'], { + refresh: true + }); + } + setAmbientPower(power) { - return this.call.send('enable_amb', [ power ? 'on' : 'off' ]) + return this.call('enable_amb', [ power ? 'on' : 'off' ]) .then(MiioApi.checkOk); } setAmbientBrightness(brightness) { brightness = percentage(brightness, { min: 0, max: 100 }); - return this.call.send('set_amb_bright', [ brightness ]) - .then(MiioApi.checkOk); + return this.call('set_amb_bright', [ brightness ], { + refresh: true + }).then(MiioApi.checkOk); } + propertyUpdated(key, value) { super.propertyUpdated(key, value);