mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 17:05:21 +01:00
Tuya Number Scaling by step value (#5108)
This commit is contained in:
parent
5751e9ec59
commit
dae8ab563c
1 changed files with 3 additions and 2 deletions
|
@ -10,7 +10,7 @@ void TuyaNumber::setup() {
|
|||
this->parent_->register_listener(this->number_id_, [this](const TuyaDatapoint &datapoint) {
|
||||
if (datapoint.type == TuyaDatapointType::INTEGER) {
|
||||
ESP_LOGV(TAG, "MCU reported number %u is: %d", datapoint.id, datapoint.value_int);
|
||||
this->publish_state(datapoint.value_int);
|
||||
this->publish_state(datapoint.value_int * this->traits.get_step());
|
||||
} else if (datapoint.type == TuyaDatapointType::ENUM) {
|
||||
ESP_LOGV(TAG, "MCU reported number %u is: %u", datapoint.id, datapoint.value_enum);
|
||||
this->publish_state(datapoint.value_enum);
|
||||
|
@ -22,7 +22,8 @@ void TuyaNumber::setup() {
|
|||
void TuyaNumber::control(float value) {
|
||||
ESP_LOGV(TAG, "Setting number %u: %f", this->number_id_, value);
|
||||
if (this->type_ == TuyaDatapointType::INTEGER) {
|
||||
this->parent_->set_integer_datapoint_value(this->number_id_, value);
|
||||
int integer_value = lround(value / this->traits.get_step());
|
||||
this->parent_->set_integer_datapoint_value(this->number_id_, integer_value);
|
||||
} else if (this->type_ == TuyaDatapointType::ENUM) {
|
||||
this->parent_->set_enum_datapoint_value(this->number_id_, value);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue