mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 18:48:28 +02:00
Break the Tuya set_datapoint_value method into separate methods per datapoint type (#2059)
Co-authored-by: Chris Nussbaum <chris.nussbaum@protolabs.com> Co-authored-by: Trevor North <trevor@freedisc.co.uk>
This commit is contained in:
@@ -31,7 +31,7 @@ void TuyaLight::setup() {
|
||||
});
|
||||
}
|
||||
if (min_value_datapoint_id_.has_value()) {
|
||||
parent_->set_datapoint_value(*this->min_value_datapoint_id_, this->min_value_);
|
||||
parent_->set_integer_datapoint_value(*this->min_value_datapoint_id_, this->min_value_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,9 +66,9 @@ void TuyaLight::write_state(light::LightState *state) {
|
||||
if (brightness == 0.0f) {
|
||||
// turning off, first try via switch (if exists), then dimmer
|
||||
if (switch_id_.has_value()) {
|
||||
parent_->set_datapoint_value(*this->switch_id_, false);
|
||||
parent_->set_boolean_datapoint_value(*this->switch_id_, false);
|
||||
} else if (dimmer_id_.has_value()) {
|
||||
parent_->set_datapoint_value(*this->dimmer_id_, 0);
|
||||
parent_->set_integer_datapoint_value(*this->dimmer_id_, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -78,17 +78,17 @@ void TuyaLight::write_state(light::LightState *state) {
|
||||
static_cast<uint32_t>(this->color_temperature_max_value_ *
|
||||
(state->current_values.get_color_temperature() - this->cold_white_temperature_) /
|
||||
(this->warm_white_temperature_ - this->cold_white_temperature_));
|
||||
parent_->set_datapoint_value(*this->color_temperature_id_, color_temp_int);
|
||||
parent_->set_integer_datapoint_value(*this->color_temperature_id_, color_temp_int);
|
||||
}
|
||||
|
||||
auto brightness_int = static_cast<uint32_t>(brightness * this->max_value_);
|
||||
brightness_int = std::max(brightness_int, this->min_value_);
|
||||
|
||||
if (this->dimmer_id_.has_value()) {
|
||||
parent_->set_datapoint_value(*this->dimmer_id_, brightness_int);
|
||||
parent_->set_integer_datapoint_value(*this->dimmer_id_, brightness_int);
|
||||
}
|
||||
if (this->switch_id_.has_value()) {
|
||||
parent_->set_datapoint_value(*this->switch_id_, true);
|
||||
parent_->set_boolean_datapoint_value(*this->switch_id_, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user