From 2b24df2a35179ab5e3665fcbb6b00c87e0ac61ac Mon Sep 17 00:00:00 2001 From: Peter Beaucage Date: Mon, 20 Jan 2025 23:40:19 -0500 Subject: [PATCH 1/2] Add brightness conversions during sets --- lib/SimpleFanLightAccessory.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/SimpleFanLightAccessory.js b/lib/SimpleFanLightAccessory.js index 7c86e6a0..bcd584c7 100644 --- a/lib/SimpleFanLightAccessory.js +++ b/lib/SimpleFanLightAccessory.js @@ -83,9 +83,11 @@ class SimpleFanLightAccessory extends BaseAccessory { if (changes.hasOwnProperty(this.dpLightOn) && characteristicLightOn && characteristicLightOn.value !== changes[this.dpLightOn]) characteristicLightOn.updateValue(changes[this.dpLightOn]); - if (changes.hasOwnProperty(this.dpBrightness) && characteristicBrightness && characteristicBrightness.value !== changes[this.dpBrightness]) - characteristicBrightness.updateValue(changes[this.dpBrightness]); - + if (changes.hasOwnProperty(this.dpBrightness) && characteristicBrightness && cha +racteristicBrightness.value !== changes[this.dpBrightness]) + characteristicBrightness.updateValue(this.convertBrightnessFromTuyaToHomeKit +(changes[this.dpBrightness])); + this.log.debug('SimpleFanLight changed: ' + JSON.stringify(state)); }); } @@ -182,23 +184,14 @@ class SimpleFanLightAccessory extends BaseAccessory { callback(); } - //Lightbulb Brightness getBrightness(callback) { - this.getState(this.dpBrightness, (err, dp) => { - if (err) return callback(err); - callback(null, this._getBrightness(dp)); - }); - } - - _getBrightness(dp) { - const {Characteristic} = this.hap; - return dp; + callback(null, this.convertBrightnessFromTuyaToHomeKit(this.device.state[this.dpBrig +htness])); } setBrightness(value, callback) { - const {Characteristic} = this.hap; - return this.setState(this.dpBrightness, value, callback); - callback(); + this.setState(this.dpBrightness, this.convertBrightnessFromHomeKitToTuya(value), cal +lback); } } From 952e94462e16a1a374e4310a71b72faf500cfd97 Mon Sep 17 00:00:00 2001 From: Peter Beaucage Date: Mon, 20 Jan 2025 23:51:58 -0500 Subject: [PATCH 2/2] Change brightness props now that conversion is handled elsewhere --- lib/SimpleFanLightAccessory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/SimpleFanLightAccessory.js b/lib/SimpleFanLightAccessory.js index bcd584c7..b594951c 100644 --- a/lib/SimpleFanLightAccessory.js +++ b/lib/SimpleFanLightAccessory.js @@ -63,8 +63,8 @@ class SimpleFanLightAccessory extends BaseAccessory { characteristicBrightness = serviceLightbulb.getCharacteristic(Characteristic.Brightness) .setProps({ minValue: 0, - maxValue: 1000, - minStep: 100 + maxValue: 100, + minStep: 1 }) .updateValue(this.convertBrightnessFromTuyaToHomeKit(dps[this.dpBrightness])) .on('get', this.getBrightness.bind(this))