From e74c31e471cc6a6de239d0deb38b6170474da235 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Sun, 16 Feb 2025 14:42:34 +0100 Subject: [PATCH] fix: round state conversion for MCP4461 wiper level to ensure accurate integer values --- esphome/components/mcp4461/output/mcp4461_output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 56ab60dae1..0afc0346cb 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -12,7 +12,7 @@ static const char *const TAG = "mcp4461.output"; // 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 void Mcp4461Wiper::write_state(float state) { - if (this->parent_->set_wiper_level_(this->wiper_, static_cast(state * 256))) { + if (this->parent_->set_wiper_level_(this->wiper_, static_cast(std::roundf(state * 256)))) { this->state_ = state; } }