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 Jesse Hills
parent 917e0f93ed
commit 2309f15ce0
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A
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