Fix #1940: Implement speed_count in TuyaFan (#1654)

Co-authored-by: Frank Riley <fhriley@gmail.com>
This commit is contained in:
0x0a11c0de
2021-05-03 19:11:24 -07:00
committed by GitHub
parent dd4fb85170
commit 98f0d75180
3 changed files with 15 additions and 16 deletions
+5 -7
View File
@@ -8,18 +8,15 @@ namespace tuya {
static const char *TAG = "tuya.fan";
void TuyaFan::setup() {
auto traits = fan::FanTraits(this->oscillation_id_.has_value(), this->speed_id_.has_value(), false, 3);
auto traits =
fan::FanTraits(this->oscillation_id_.has_value(), this->speed_id_.has_value(), false, this->speed_count_);
this->fan_->set_traits(traits);
if (this->speed_id_.has_value()) {
this->parent_->register_listener(*this->speed_id_, [this](TuyaDatapoint datapoint) {
auto call = this->fan_->make_call();
if (datapoint.value_enum == 0x0)
call.set_speed(1);
else if (datapoint.value_enum == 0x1)
call.set_speed(2);
else if (datapoint.value_enum == 0x2)
call.set_speed(3);
if (datapoint.value_enum < this->speed_count_)
call.set_speed(datapoint.value_enum + 1);
else
ESP_LOGCONFIG(TAG, "Speed has invalid value %d", datapoint.value_enum);
ESP_LOGD(TAG, "MCU reported speed of: %d", datapoint.value_enum);
@@ -47,6 +44,7 @@ void TuyaFan::setup() {
void TuyaFan::dump_config() {
ESP_LOGCONFIG(TAG, "Tuya Fan:");
ESP_LOGCONFIG(TAG, " Speed count %d", this->speed_count_);
if (this->speed_id_.has_value())
ESP_LOGCONFIG(TAG, " Speed has datapoint ID %u", *this->speed_id_);
if (this->switch_id_.has_value())