Skip to content

Commit

Permalink
Fix philips bulb light
Browse files Browse the repository at this point in the history
  • Loading branch information
einstweilenhier authored and aholstenson committed Feb 17, 2018
1 parent 88517cf commit 84b8a15
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 14 additions & 0 deletions lib/devices/capabilities/colorable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const { Thing } = require('abstract-things');
const { Colorable } = require('abstract-things/lights');

module.exports = Thing.mixin(Parent => class extends Parent.with(Colorable) {
propertyUpdated(key, value) {
if(key === 'color') {
this.updateColor(value);
}

super.propertyUpdated(key, value);
}
});
13 changes: 7 additions & 6 deletions lib/devices/philips-light-bulb.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const { LightBulb, Colorable, ColorTemperature } = require('abstract-things/lights');
const { LightBulb, ColorTemperature } = require('abstract-things/lights');
const { color } = require('abstract-things/values');
const MiioApi = require('../device');

const Power = require('./capabilities/power');
const Dimmable = require('./capabilities/dimmable');
const Colorable = require('./capabilities/colorable');

const MIN_TEMP = 3000;
const MAX_TEMP = 5700;
Expand All @@ -31,7 +32,7 @@ module.exports = class BallLamp extends LightBulb
});

this.defineProperty('cct', {
name: 'colorTemperature',
name: 'color',
mapper: v => {
v = parseInt(v);
return color.temperature(MIN_TEMP + (v / 100) * (MAX_TEMP - MIN_TEMP));
Expand All @@ -41,10 +42,10 @@ module.exports = class BallLamp extends LightBulb
this.updateColorTemperatureRange(MIN_TEMP, MAX_TEMP);
}

updatePower(power) {
changePower(power) {
return this.call('set_power', [ power ? 'on' : 'off' ], {
refresh: [ 'power' ]
});
}).then(MiioApi.checkOk);
}

changeBrightness(brightness) {
Expand All @@ -57,15 +58,15 @@ module.exports = class BallLamp extends LightBulb
const kelvins = color.temperature.kelvins;
let temp;
if(kelvins <= MIN_TEMP) {
temp = 0;
temp = 1;
} else if(kelvins >= MAX_TEMP) {
temp = 100;
} else {
temp = Math.round((kelvins - MIN_TEMP) / (MAX_TEMP - MIN_TEMP) * 100);
}

return this.call('set_cct', [ temp ], {
refresh: [ 'colorTemperature ']
refresh: [ 'color']
}).then(MiioApi.checkOk);
}

Expand Down

0 comments on commit 84b8a15

Please sign in to comment.