Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and enhance Philips Eyecare Smart Lamp 2 support #238

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions lib/devices/eyecare-lamp2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
});

Expand All @@ -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);
Expand All @@ -112,8 +117,8 @@ module.exports = class EyecareLamp2 extends Light

/**
* Set the current eyeCare mode
*
changeMode(mode) {
*/
setMode(mode) {

switch (mode) {
case 'study':
Expand All @@ -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);

Expand Down