mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-03 19:38:30 +02:00
Support fan speed levels (#1541)
* Add fan speed percentage support to the API * Add float fan speed percentage * Add percentage support to automation and configuration * Update Tuya fan * Fix pylint warning * Update API to use speed levels instead of percentage * Use speed levels * Fix type warnings * MQTT component now converts between speed levels and enums * Webserver now supports speed_level * Update prometheus * Remove low/medium/high settings from speed fan * Remove unused enum * Configurable speed levels for speed fan * Remove unused import * Rename speed_level->speed and speed_levels->speed_count * Rename supported_speed_levels -> supported_speed_count in API and FanTraits Field id stays the same in the protocol, so the change is not breaking for aioesphome.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/components/fan/fan_helpers.h"
|
||||
#include "tuya_fan.h"
|
||||
|
||||
namespace esphome {
|
||||
@@ -7,18 +8,18 @@ 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);
|
||||
auto traits = fan::FanTraits(this->oscillation_id_.has_value(), this->speed_id_.has_value(), false, 3);
|
||||
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(fan::FAN_SPEED_LOW);
|
||||
call.set_speed(1);
|
||||
else if (datapoint.value_enum == 0x1)
|
||||
call.set_speed(fan::FAN_SPEED_MEDIUM);
|
||||
call.set_speed(2);
|
||||
else if (datapoint.value_enum == 0x2)
|
||||
call.set_speed(fan::FAN_SPEED_HIGH);
|
||||
call.set_speed(3);
|
||||
else
|
||||
ESP_LOGCONFIG(TAG, "Speed has invalid value %d", datapoint.value_enum);
|
||||
ESP_LOGD(TAG, "MCU reported speed of: %d", datapoint.value_enum);
|
||||
@@ -75,12 +76,7 @@ void TuyaFan::write_state() {
|
||||
TuyaDatapoint datapoint{};
|
||||
datapoint.id = *this->speed_id_;
|
||||
datapoint.type = TuyaDatapointType::ENUM;
|
||||
if (this->fan_->speed == fan::FAN_SPEED_LOW)
|
||||
datapoint.value_enum = 0;
|
||||
if (this->fan_->speed == fan::FAN_SPEED_MEDIUM)
|
||||
datapoint.value_enum = 1;
|
||||
if (this->fan_->speed == fan::FAN_SPEED_HIGH)
|
||||
datapoint.value_enum = 2;
|
||||
datapoint.value_enum = this->fan_->speed - 1;
|
||||
ESP_LOGD(TAG, "Setting speed: %d", datapoint.value_enum);
|
||||
this->parent_->set_datapoint_value(datapoint);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user