From fd87c9a9c6bb2cf9ab800305dc8d438b55af0520 Mon Sep 17 00:00:00 2001 From: Mikhail Smirnov Date: Sat, 19 Jan 2019 21:43:00 +0300 Subject: [PATCH 1/2] Adding support for Philips ZhiRui Downlight --- lib/devices/philips-light-downlight.js | 73 ++++++++++++++++++++++++++ lib/models.js | 3 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 lib/devices/philips-light-downlight.js diff --git a/lib/devices/philips-light-downlight.js b/lib/devices/philips-light-downlight.js new file mode 100644 index 0000000..8830e3f --- /dev/null +++ b/lib/devices/philips-light-downlight.js @@ -0,0 +1,73 @@ +'use strict'; + +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; + +module.exports = class BallLamp extends LightBulb + .with(MiioApi, Power, Dimmable, Colorable, ColorTemperature) +{ + static get type() { + return 'miio:philiphs-ball-lamp'; + } + + constructor(options) { + super(options); + + this.defineProperty('power', { + name: 'power', + mapper: v => v === 'on' + }); + + this.defineProperty('bright', { + name: 'brightness', + mapper: parseInt + }); + + this.defineProperty('cct', { + name: 'color', + mapper: v => { + v = parseInt(v); + return color.temperature(MIN_TEMP + (v / 100) * (MAX_TEMP - MIN_TEMP)); + } + }); + + this.updateColorTemperatureRange(MIN_TEMP, MAX_TEMP); + } + + changePower(power) { + return this.call('set_power', [ power ? 'on' : 'off' ], { + refresh: [ 'power' ] + }).then(MiioApi.checkOk); + } + + changeBrightness(brightness) { + return this.call('set_bright', [ brightness ], { + refresh: [ 'brightness' ] + }).then(MiioApi.checkOk); + } + + changeColor(color) { + const kelvins = color.temperature.kelvins; + let temp; + if(kelvins <= MIN_TEMP) { + 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: [ 'color'] + }).then(MiioApi.checkOk); + } + +}; diff --git a/lib/models.js b/lib/models.js index 635c453..a78ff43 100644 --- a/lib/models.js +++ b/lib/models.js @@ -57,6 +57,7 @@ module.exports = { 'yeelink.light.strip1': YeelightColor, 'philips.light.sread1': require('./devices/eyecare-lamp2'), - 'philips.light.bulb': require('./devices/philips-light-bulb') + 'philips.light.bulb': require('./devices/philips-light-bulb'), + 'philips.light.downlight': require('./devices/philips-light-downlight') }; From 6b3f53062ae4753f9e19eef747d9c013aec59af7 Mon Sep 17 00:00:00 2001 From: Mikhail Smirnov Date: Sat, 23 Feb 2019 18:10:06 +0300 Subject: [PATCH 2/2] Adding support for Philips ZhiRui Downlight --- lib/devices/philips-light-downlight.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/devices/philips-light-downlight.js b/lib/devices/philips-light-downlight.js index 8830e3f..fca7802 100644 --- a/lib/devices/philips-light-downlight.js +++ b/lib/devices/philips-light-downlight.js @@ -15,7 +15,7 @@ module.exports = class BallLamp extends LightBulb .with(MiioApi, Power, Dimmable, Colorable, ColorTemperature) { static get type() { - return 'miio:philiphs-ball-lamp'; + return 'miio: philips-light-downlight'; } constructor(options) {