Fix - Tuya Fan - Allow integer speed datapoint (#5948)

Co-authored-by: Cram42 <5396871+cram42@users.noreply.github.com>
This commit is contained in:
Grant Le Roux 2023-12-18 07:28:48 +08:00 committed by GitHub
parent 94904f44f9
commit 003d8b0cf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -9,6 +9,7 @@ static const char *const TAG = "tuya.fan";
void TuyaFan::setup() {
if (this->speed_id_.has_value()) {
this->parent_->register_listener(*this->speed_id_, [this](const TuyaDatapoint &datapoint) {
if (datapoint.type == TuyaDatapointType::ENUM) {
ESP_LOGV(TAG, "MCU reported speed of: %d", datapoint.value_enum);
if (datapoint.value_enum >= this->speed_count_) {
ESP_LOGE(TAG, "Speed has invalid value %d", datapoint.value_enum);
@ -16,6 +17,12 @@ void TuyaFan::setup() {
this->speed = datapoint.value_enum + 1;
this->publish_state();
}
} else if (datapoint.type == TuyaDatapointType::INTEGER) {
ESP_LOGV(TAG, "MCU reported speed of: %d", datapoint.value_int);
this->speed = datapoint.value_int;
this->publish_state();
}
this->speed_type_ = datapoint.type;
});
}
if (this->switch_id_.has_value()) {
@ -80,7 +87,11 @@ void TuyaFan::control(const fan::FanCall &call) {
this->parent_->set_enum_datapoint_value(*this->direction_id_, enable);
}
if (this->speed_id_.has_value() && call.get_speed().has_value()) {
if (this->speed_type_ == TuyaDatapointType::ENUM) {
this->parent_->set_enum_datapoint_value(*this->speed_id_, *call.get_speed() - 1);
} else if (this->speed_type_ == TuyaDatapointType::INTEGER) {
this->parent_->set_integer_datapoint_value(*this->speed_id_, *call.get_speed());
}
}
}

View File

@ -28,6 +28,7 @@ class TuyaFan : public Component, public fan::Fan {
optional<uint8_t> oscillation_id_{};
optional<uint8_t> direction_id_{};
int speed_count_{};
TuyaDatapointType speed_type_{};
};
} // namespace tuya