Tuya Number Scaling by step value (#5108)

This commit is contained in:
Marc J 2023-09-27 00:45:21 -07:00 committed by Jesse Hills
parent 5751e9ec59
commit dae8ab563c
No known key found for this signature in database
GPG key ID: BEAAE804EFD8E83A

View file

@ -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);
}