mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 13:24:15 +01:00
Fix - Tuya Fan - Allow integer speed datapoint (#5948)
Co-authored-by: Cram42 <5396871+cram42@users.noreply.github.com>
This commit is contained in:
parent
94904f44f9
commit
003d8b0cf5
@ -9,6 +9,7 @@ static const char *const TAG = "tuya.fan";
|
|||||||
void TuyaFan::setup() {
|
void TuyaFan::setup() {
|
||||||
if (this->speed_id_.has_value()) {
|
if (this->speed_id_.has_value()) {
|
||||||
this->parent_->register_listener(*this->speed_id_, [this](const TuyaDatapoint &datapoint) {
|
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);
|
ESP_LOGV(TAG, "MCU reported speed of: %d", datapoint.value_enum);
|
||||||
if (datapoint.value_enum >= this->speed_count_) {
|
if (datapoint.value_enum >= this->speed_count_) {
|
||||||
ESP_LOGE(TAG, "Speed has invalid value %d", datapoint.value_enum);
|
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->speed = datapoint.value_enum + 1;
|
||||||
this->publish_state();
|
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()) {
|
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);
|
this->parent_->set_enum_datapoint_value(*this->direction_id_, enable);
|
||||||
}
|
}
|
||||||
if (this->speed_id_.has_value() && call.get_speed().has_value()) {
|
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);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ class TuyaFan : public Component, public fan::Fan {
|
|||||||
optional<uint8_t> oscillation_id_{};
|
optional<uint8_t> oscillation_id_{};
|
||||||
optional<uint8_t> direction_id_{};
|
optional<uint8_t> direction_id_{};
|
||||||
int speed_count_{};
|
int speed_count_{};
|
||||||
|
TuyaDatapointType speed_type_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tuya
|
} // namespace tuya
|
||||||
|
Loading…
Reference in New Issue
Block a user