From 5e4448898acb5515e94509179980b69c571453f4 Mon Sep 17 00:00:00 2001 From: einstweilenhier <17862290+einstweilenhier@users.noreply.github.com> Date: Wed, 14 Feb 2018 13:17:39 +0100 Subject: [PATCH] Fix philips bulb light --- lib/devices/capabilities/colorable.js | 14 ++++++++++++++ lib/devices/philips-light-bulb.js | 13 +++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 lib/devices/capabilities/colorable.js diff --git a/lib/devices/capabilities/colorable.js b/lib/devices/capabilities/colorable.js new file mode 100644 index 0000000..97fd2c3 --- /dev/null +++ b/lib/devices/capabilities/colorable.js @@ -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); + } +}); diff --git a/lib/devices/philips-light-bulb.js b/lib/devices/philips-light-bulb.js index da90957..8830e3f 100644 --- a/lib/devices/philips-light-bulb.js +++ b/lib/devices/philips-light-bulb.js @@ -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; @@ -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)); @@ -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) { @@ -57,7 +58,7 @@ 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 { @@ -65,7 +66,7 @@ module.exports = class BallLamp extends LightBulb } return this.call('set_cct', [ temp ], { - refresh: [ 'colorTemperature '] + refresh: [ 'color'] }).then(MiioApi.checkOk); }