From 7696042d4a4c0922e1cf0d4751d93d4cdbace42b Mon Sep 17 00:00:00 2001 From: Alex Shestakov Date: Sun, 30 Jun 2019 02:25:33 +0300 Subject: [PATCH 1/2] Fix Philips Eyecare Smart Lamp 2 support and add comments to props according to Mi Home app --- lib/devices/eyecare-lamp2.js | 49 +++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/devices/eyecare-lamp2.js b/lib/devices/eyecare-lamp2.js index 35250c7..960ab96 100644 --- a/lib/devices/eyecare-lamp2.js +++ b/lib/devices/eyecare-lamp2.js @@ -4,13 +4,13 @@ const MiioApi = require('../device'); const { Children } = require('abstract-things'); const { Light, Dimmable, SwitchablePower } = require('abstract-things/lights'); -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 +26,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 +38,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 +65,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 }); @@ -112,8 +114,8 @@ module.exports = class EyecareLamp2 extends Light /** * Set the current eyeCare mode - * - changeMode(mode) { + */ + setMode(mode) { switch (mode) { case 'study': @@ -132,20 +134,39 @@ 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); From f4e28cde8487c8b4df0d26c02b541ed1445a8e5a Mon Sep 17 00:00:00 2001 From: Alex Shestakov Date: Sun, 30 Jun 2019 02:35:01 +0300 Subject: [PATCH 2/2] Add brightness range coercion --- lib/devices/eyecare-lamp2.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/devices/eyecare-lamp2.js b/lib/devices/eyecare-lamp2.js index 960ab96..a96583a 100644 --- a/lib/devices/eyecare-lamp2.js +++ b/lib/devices/eyecare-lamp2.js @@ -4,6 +4,7 @@ const MiioApi = require('../device'); const { Children } = require('abstract-things'); const { Light, Dimmable, SwitchablePower } = require('abstract-things/lights'); +const { percentage } = require('abstract-things/values'); const MiioDimmable = require('./capabilities/dimmable'); const MiioPower = require('./capabilities/power'); @@ -90,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); @@ -160,6 +163,7 @@ module.exports = class EyecareLamp2 extends Light } setAmbientBrightness(brightness) { + brightness = percentage(brightness, { min: 0, max: 100 }); return this.call('set_amb_bright', [ brightness ], { refresh: true