From 231c5a21a1e4eaed66caedeff2e5f6798237b615 Mon Sep 17 00:00:00 2001 From: Konstantin Kabanov Date: Sun, 17 Dec 2023 14:33:10 +0700 Subject: [PATCH 1/3] Add color flow mode support --- bulbs/colorflow.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++ platform.js | 5 ++++ 2 files changed, 74 insertions(+) create mode 100644 bulbs/colorflow.js diff --git a/bulbs/colorflow.js b/bulbs/colorflow.js new file mode 100644 index 0000000..c52165a --- /dev/null +++ b/bulbs/colorflow.js @@ -0,0 +1,69 @@ +const COLOR_FLOW_DISABLED = 0; +const COLOR_FLOW_ENABLED = 1; + +const ColorFlowMode = (Device) => + class extends Device { + constructor(props, platform) { + super(props, platform); + this.initColorFlow(); + } + + async initColorFlow() { + const [flowing] = await this.getProperty(['flowing']); + if (!flowing) return; + + this.log(`Device ${this.name} supports color flow mode`); + this.flowing = Number(flowing) || COLOR_FLOW_DISABLED; + + this.colorFlowService = + this.accessory.getService(global.Service.Switch) || + this.accessory.addService(new global.Service.Switch(`Color Flow Mode`)); + + this.colorFlowService + .getCharacteristic(global.Characteristic.On) + .on('set', async (value, callback) => { + try { + await this.setColorFlowMode(value); + callback(null); + } catch (err) { + callback(err); + } + }) + .on('get', async (callback) => { + try { + const [value] = await this.getProperty(['flowing']); + this.flowing = Number(value); + callback(null, this.flowing); + } catch (err) { + callback(err, this.flowing); + } + }) + .updateValue(this.flowing); + } + + async setColorFlowMode(state) { + const { brightness: transition = 400 } = this.config.transitions || {}; + this.log.debug( + `${state ? 'Enabling' : 'Disabling'} color flow mode on device ${this.did}` + ); + await this.sendCmd({ + method: 'set_power', + params: ['on', 'smooth', transition, state ? 4 : 1], + }); + this.flowing = state ? COLOR_FLOW_ENABLED : COLOR_FLOW_DISABLED; + } + + updateStateFromProp(prop, value) { + if (prop === 'flowing') { + this.flowing = value; + this.colorFlowService + .getCharacteristic(global.Characteristic.On) + .updateValue(this.flowing === COLOR_FLOW_ENABLED); + return; + } + + super.updateStateFromProp(prop, value); + } + }; + +module.exports = ColorFlowMode; diff --git a/platform.js b/platform.js index 6a55bc7..4edf576 100644 --- a/platform.js +++ b/platform.js @@ -3,6 +3,7 @@ const devices = require('./devices.json'); const YeeBulb = require('./bulbs/bulb'); const Brightness = require('./bulbs/brightness'); const MoonlightMode = require('./bulbs/moonlight'); +const ColorFlowMode = require('./bulbs/colorflow'); const Color = require('./bulbs/color'); const Temperature = require('./bulbs/temperature'); const Backlight = require('./bulbs/backlight/bulb'); @@ -132,6 +133,10 @@ class YeePlatform { mixins.push(MoonlightMode); } + if (!hidden.includes('flowing')) { + mixins.push(ColorFlowMode); + } + if (features.includes('set_bright')) { this.log(`Device ${name} supports brightness`); mixins.push(Brightness); From 8910cfb803d1456db0f063dbbea2132482b827c9 Mon Sep 17 00:00:00 2001 From: Konstantin Kabanov Date: Sun, 17 Dec 2023 15:00:54 +0700 Subject: [PATCH 2/3] Fix getting color flow switch service --- bulbs/colorflow.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bulbs/colorflow.js b/bulbs/colorflow.js index c52165a..2278713 100644 --- a/bulbs/colorflow.js +++ b/bulbs/colorflow.js @@ -16,7 +16,7 @@ const ColorFlowMode = (Device) => this.flowing = Number(flowing) || COLOR_FLOW_DISABLED; this.colorFlowService = - this.accessory.getService(global.Service.Switch) || + this.accessory.getService(`Color Flow Mode`) || this.accessory.addService(new global.Service.Switch(`Color Flow Mode`)); this.colorFlowService From 4a008f30a071a9651fde5c12ae9e69f4c30a2e30 Mon Sep 17 00:00:00 2001 From: Konstantin Kabanov Date: Mon, 18 Dec 2023 12:29:30 +0700 Subject: [PATCH 3/3] Fix getting color flow switch service --- bulbs/colorflow.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bulbs/colorflow.js b/bulbs/colorflow.js index 2278713..58b1103 100644 --- a/bulbs/colorflow.js +++ b/bulbs/colorflow.js @@ -16,8 +16,8 @@ const ColorFlowMode = (Device) => this.flowing = Number(flowing) || COLOR_FLOW_DISABLED; this.colorFlowService = - this.accessory.getService(`Color Flow Mode`) || - this.accessory.addService(new global.Service.Switch(`Color Flow Mode`)); + this.accessory.getService('color_flow') || + this.accessory.addService(new global.Service.Switch('Color Flow Mode', 'color_flow')); this.colorFlowService .getCharacteristic(global.Characteristic.On)