Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inversed colour temperature. #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/light_accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class LightAccessory extends BaseAccessory {
var rawValue;
var temperature;
rawValue = this.tempValue.value;
temperature = Math.floor((rawValue - this.function_dp_range.temp_range.min) * 360 / (this.function_dp_range.temp_range.max - this.function_dp_range.temp_range.min) + 140); // ra$
temperature = Math.floor(1000000/((rawValue - this.function_dp_range.temp_range.min) * 12285 / (this.function_dp_range.temp_range.max - this.function_dp_range.temp_range.min) + 2000)); // ra$
if (temperature > 500) {
temperature = 500
temperature = 500;
}
if (temperature < 140) {
temperature = 140
if (temperature < 70) {
temperature = 70;
}
this.normalAsync(Characteristic.ColorTemperature, temperature)
}
Expand Down Expand Up @@ -123,6 +123,11 @@ class LightAccessory extends BaseAccessory {
callback(error);
});
});

//Extend the range of the ColorTemperature characteristic so the UI will show a better looking orange to blue gradient.
if (name == Characteristic.ColorTemperature) {
this.service.getCharacteristic(name).setProps({minValue:70,maxValue:500});
}
}

//get Command SendData
Expand All @@ -137,7 +142,7 @@ class LightAccessory extends BaseAccessory {
break;
case Characteristic.ColorTemperature:
var temperature;
temperature = Math.floor((value - 140) * (this.function_dp_range.temp_range.max - this.function_dp_range.temp_range.min) / 360 + this.function_dp_range.temp_range.min); // value 140~500
temperature = Math.floor((1000000/value - 2000) * (this.function_dp_range.temp_range.max - this.function_dp_range.temp_range.min) / 12285 + this.function_dp_range.temp_range.min); // value 70~500
code = this.tempValue.code;
value = temperature;
break;
Expand Down