mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Block Tuya light from reacting to dp changes if transitioning (#3076)
This commit is contained in:
parent
ebca936b7e
commit
6a85259e4d
1 changed files with 25 additions and 0 deletions
|
@ -10,6 +10,11 @@ static const char *const TAG = "tuya.light";
|
||||||
void TuyaLight::setup() {
|
void TuyaLight::setup() {
|
||||||
if (this->color_temperature_id_.has_value()) {
|
if (this->color_temperature_id_.has_value()) {
|
||||||
this->parent_->register_listener(*this->color_temperature_id_, [this](const TuyaDatapoint &datapoint) {
|
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;
|
auto datapoint_value = datapoint.value_uint;
|
||||||
if (this->color_temperature_invert_) {
|
if (this->color_temperature_invert_) {
|
||||||
datapoint_value = this->color_temperature_max_value_ - datapoint_value;
|
datapoint_value = this->color_temperature_max_value_ - datapoint_value;
|
||||||
|
@ -23,6 +28,11 @@ void TuyaLight::setup() {
|
||||||
}
|
}
|
||||||
if (this->dimmer_id_.has_value()) {
|
if (this->dimmer_id_.has_value()) {
|
||||||
this->parent_->register_listener(*this->dimmer_id_, [this](const TuyaDatapoint &datapoint) {
|
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();
|
auto call = this->state_->make_call();
|
||||||
call.set_brightness(float(datapoint.value_uint) / this->max_value_);
|
call.set_brightness(float(datapoint.value_uint) / this->max_value_);
|
||||||
call.perform();
|
call.perform();
|
||||||
|
@ -30,6 +40,11 @@ void TuyaLight::setup() {
|
||||||
}
|
}
|
||||||
if (switch_id_.has_value()) {
|
if (switch_id_.has_value()) {
|
||||||
this->parent_->register_listener(*this->switch_id_, [this](const TuyaDatapoint &datapoint) {
|
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();
|
auto call = this->state_->make_call();
|
||||||
call.set_state(datapoint.value_bool);
|
call.set_state(datapoint.value_bool);
|
||||||
call.perform();
|
call.perform();
|
||||||
|
@ -41,6 +56,11 @@ void TuyaLight::setup() {
|
||||||
auto green = parse_hex<uint8_t>(datapoint.value_string.substr(2, 2));
|
auto green = parse_hex<uint8_t>(datapoint.value_string.substr(2, 2));
|
||||||
auto blue = parse_hex<uint8_t>(datapoint.value_string.substr(4, 2));
|
auto blue = parse_hex<uint8_t>(datapoint.value_string.substr(4, 2));
|
||||||
if (red.has_value() && green.has_value() && blue.has_value()) {
|
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();
|
auto call = this->state_->make_call();
|
||||||
call.set_rgb(float(*red) / 255, float(*green) / 255, float(*blue) / 255);
|
call.set_rgb(float(*red) / 255, float(*green) / 255, float(*blue) / 255);
|
||||||
call.perform();
|
call.perform();
|
||||||
|
@ -52,6 +72,11 @@ void TuyaLight::setup() {
|
||||||
auto saturation = parse_hex<uint16_t>(datapoint.value_string.substr(4, 4));
|
auto saturation = parse_hex<uint16_t>(datapoint.value_string.substr(4, 4));
|
||||||
auto value = parse_hex<uint16_t>(datapoint.value_string.substr(8, 4));
|
auto value = parse_hex<uint16_t>(datapoint.value_string.substr(8, 4));
|
||||||
if (hue.has_value() && saturation.has_value() && value.has_value()) {
|
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;
|
float red, green, blue;
|
||||||
hsv_to_rgb(*hue, float(*saturation) / 1000, float(*value) / 1000, red, green, blue);
|
hsv_to_rgb(*hue, float(*saturation) / 1000, float(*value) / 1000, red, green, blue);
|
||||||
auto call = this->state_->make_call();
|
auto call = this->state_->make_call();
|
||||||
|
|
Loading…
Reference in a new issue