Skip to content

Commit

Permalink
Merge pull request #266 from iRayanKhan/ElphaX-patch-2-1
Browse files Browse the repository at this point in the history
Fixed Brightness
  • Loading branch information
iRayanKhan committed May 5, 2021
2 parents 9603aa8 + 64ff0a9 commit ea48ede
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions lib/OilDiffuserAccessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class OilDiffuserAccessory extends BaseAccessory {
super(...props);
}

// function to return true if the garage door manufacturer is BelleLife
_isBelleLife() {
if (this.device.context.manufacturer.trim().toLowerCase() === 'bellelife') {
return true;
Expand All @@ -19,7 +18,6 @@ class OilDiffuserAccessory extends BaseAccessory {
}
}

// function to return true if the garage door manufacturer is BelleLife
_isGeeni() {
if (this.device.context.manufacturer.trim().toLowerCase() === 'geeni') {
return true;
Expand Down Expand Up @@ -76,7 +74,6 @@ class OilDiffuserAccessory extends BaseAccessory {
this.dpLight = this._getCustomDP(this.device.context.dpLight) || '5';
this.dpMode = this._getCustomDP(this.device.context.dpMode) || '6';
this.dpColor = this._getCustomDP(this.device.context.dpColor) || '8';

this.dpActive = this._getCustomDP(this.device.context.dpActive) || '1';
this.dpRotationSpeed = this._getCustomDP(this.device.context.dpRotationSpeed) || '2';
this.dpWaterLevel = this._getCustomDP(this.device.context.dpWaterLevel) || '9';
Expand Down Expand Up @@ -117,7 +114,6 @@ class OilDiffuserAccessory extends BaseAccessory {
else throw new Error(`The cmdColour doesn't appear to be valid: ${this.device.context.cmdColour}`);
}


// Led Light

const characteristicLightOn = lightService.getCharacteristic(Characteristic.On)
Expand Down Expand Up @@ -167,7 +163,6 @@ class OilDiffuserAccessory extends BaseAccessory {
.updateValue(this._getActive(dps[this.dpActive]))
.on('get', this.getActive.bind(this))
.on('set', this.setActive.bind(this));


humidifierService.getCharacteristic(Characteristic.CurrentHumidifierDehumidifierState)
.updateValue(this._getCurrentHumidifierDehumidifierState(dps))
Expand Down Expand Up @@ -207,7 +202,7 @@ class OilDiffuserAccessory extends BaseAccessory {


this.device.on('change', (changes, state) => {
//if (changes.hasOwnProperty(this.dpLight) && characteristicLightOn.value !== changes[this.dpLight]) characteristicLightOn.updateValue(changes[this.dpLight]);
if (changes.hasOwnProperty(this.dpLight) && characteristicLightOn.value !== changes[this.dpLight]) characteristicLightOn.updateValue(changes[this.dpLight]);

if (changes.hasOwnProperty(this.dpActive)) {
const newActive = this._getActive(changes[this.dpActive]);
Expand Down Expand Up @@ -248,8 +243,14 @@ class OilDiffuserAccessory extends BaseAccessory {
}

setBrightness(value, callback) {
if (this.device.state[this.dpMode] === this.cmdWhite) return this.setState((this.dpColor).b, this.convertBrightnessFromHomeKitToTuya({b: value}), callback);
this.setState(this.dpColor, this.convertColorFromHomeKitToTuya({b: value}), callback);
if(value === 0) {
return this.setState(this.dpLight, false, callback);
}
else {
if (this.device.state[this.dpMode] === this.cmdWhite) return this.setState((this.dpColor).b, this.convertBrightnessFromHomeKitToTuya({b: value}), callback);
this.device.state[this.dpMode] = this.cmdColor;
this.setMultiState({[this.dpMode]: this.cmdColor, [this.dpColor]: this.convertColorFromHomeKitToTuya({b: value})}, callback);
}
}

getColorTemperature(callback) {
Expand All @@ -265,14 +266,9 @@ class OilDiffuserAccessory extends BaseAccessory {

this.characteristicHue.updateValue(newColor.h);
this.characteristicSaturation.updateValue(newColor.s);

// Avoid cross-mode complications due rapid commands
this.device.state[this.dpMode] = this.cmdColor;

// Check for change in Color and setState if changed
if (newColor.h !== oldColor.h || newColor.s !== oldColor.s || newColor.b !== oldColor.b){
this.setMultiState({[this.dpMode]: this.cmdColor, [this.dpColor]: this.convertColorFromHomeKitToTuya(newColor)}, callback);
}
this.setMultiState({[this.dpMode]: this.cmdColor, [this.dpColor]: this.convertColorFromHomeKitToTuya(newColor)}, callback);
}

getHue(callback) {
Expand Down Expand Up @@ -309,7 +305,6 @@ class OilDiffuserAccessory extends BaseAccessory {
return;
}


const callbacks = this._pendingHueSaturation.callbacks;
const callEachBack = err => {
async.eachSeries(callbacks, (callback, next) => {
Expand All @@ -324,8 +319,6 @@ class OilDiffuserAccessory extends BaseAccessory {
const newValue = this.convertColorFromHomeKitToTuya(this._pendingHueSaturation.props);
this._pendingHueSaturation = null;

// Avoid cross-mode complications due rapid commands
this.device.state[this.dpMode] = this.cmdColor;
this.setMultiState({[this.dpMode]: this.cmdColor, [this.dpColor]: newValue}, callEachBack);
}

Expand All @@ -346,7 +339,6 @@ class OilDiffuserAccessory extends BaseAccessory {
const {Characteristic} = this.hap;
switch (value) {
case Characteristic.Active.ACTIVE:
//return this.setMultiState({[this.dpActive]: true, [this.dpRotationSpeed]: this.convertRotationSpeedFromHomeKitToTuya(this.characteristicRotationSpeed.value)}, callback);
return this.setState(this.dpActive, true, callback);

case Characteristic.Active.INACTIVE:
Expand Down

0 comments on commit ea48ede

Please sign in to comment.