Block Tuya light from reacting to dp changes if transitioning (#3076)

This commit is contained in:
VitaliyKurokhtin 2022-06-07 04:07:08 -07:00 committed by GitHub
parent ebca936b7e
commit 6a85259e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,11 @@ static const char *const TAG = "tuya.light";
void TuyaLight::setup() {
if (this->color_temperature_id_.has_value()) {
this->parent_->register_listener(*this->color_temperature_id_, [this](const TuyaDatapoint &datapoint) {
if (this->state_->current_values != this->state_->remote_values) {
ESP_LOGD(TAG, "Light is transitioning, datapoint change ignored");
return;
}
auto datapoint_value = datapoint.value_uint;
if (this->color_temperature_invert_) {
datapoint_value = this->color_temperature_max_value_ - datapoint_value;
@ -23,6 +28,11 @@ void TuyaLight::setup() {
}
if (this->dimmer_id_.has_value()) {
this->parent_->register_listener(*this->dimmer_id_, [this](const TuyaDatapoint &datapoint) {
if (this->state_->current_values != this->state_->remote_values) {
ESP_LOGD(TAG, "Light is transitioning, datapoint change ignored");
return;
}
auto call = this->state_->make_call();
call.set_brightness(float(datapoint.value_uint) / this->max_value_);
call.perform();
@ -30,6 +40,11 @@ void TuyaLight::setup() {
}
if (switch_id_.has_value()) {
this->parent_->register_listener(*this->switch_id_, [this](const TuyaDatapoint &datapoint) {
if (this->state_->current_values != this->state_->remote_values) {
ESP_LOGD(TAG, "Light is transitioning, datapoint change ignored");
return;
}
auto call = this->state_->make_call();
call.set_state(datapoint.value_bool);
call.perform();
@ -41,6 +56,11 @@ void TuyaLight::setup() {
auto green = parse_hex<uint8_t>(datapoint.value_string.substr(2, 2));
auto blue = parse_hex<uint8_t>(datapoint.value_string.substr(4, 2));
if (red.has_value() && green.has_value() && blue.has_value()) {
if (this->state_->current_values != this->state_->remote_values) {
ESP_LOGD(TAG, "Light is transitioning, datapoint change ignored");
return;
}
auto call = this->state_->make_call();
call.set_rgb(float(*red) / 255, float(*green) / 255, float(*blue) / 255);
call.perform();
@ -52,6 +72,11 @@ void TuyaLight::setup() {
auto saturation = parse_hex<uint16_t>(datapoint.value_string.substr(4, 4));
auto value = parse_hex<uint16_t>(datapoint.value_string.substr(8, 4));
if (hue.has_value() && saturation.has_value() && value.has_value()) {
if (this->state_->current_values != this->state_->remote_values) {
ESP_LOGD(TAG, "Light is transitioning, datapoint change ignored");
return;
}
float red, green, blue;
hsv_to_rgb(*hue, float(*saturation) / 1000, float(*value) / 1000, red, green, blue);
auto call = this->state_->make_call();