1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-07 22:02:22 +01:00

fix: round state conversion for MCP4461 wiper level to ensure accurate integer values

This commit is contained in:
Oliver Kleinecke
2025-02-16 14:42:34 +01:00
parent 3beefc1e4b
commit e74c31e471

View File

@@ -12,7 +12,7 @@ static const char *const TAG = "mcp4461.output";
// floats from other components (like light etc.) are passed as "percentage floats" // floats from other components (like light etc.) are passed as "percentage floats"
// this function converts them to the 0 - 256 range used by the MCP4461 // this function converts them to the 0 - 256 range used by the MCP4461
void Mcp4461Wiper::write_state(float state) { void Mcp4461Wiper::write_state(float state) {
if (this->parent_->set_wiper_level_(this->wiper_, static_cast<uint16_t>(state * 256))) { if (this->parent_->set_wiper_level_(this->wiper_, static_cast<uint16_t>(std::roundf(state * 256)))) {
this->state_ = state; this->state_ = state;
} }
} }