From c692bfecc86d1d47794728fce0ba7bb4a6ec682f Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Fri, 20 Dec 2024 17:32:32 +0100 Subject: [PATCH] Fix bathroom heater ever increasing temperature --- bathroomheater/zehnder.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bathroomheater/zehnder.h b/bathroomheater/zehnder.h index 1dfefae..9090031 100644 --- a/bathroomheater/zehnder.h +++ b/bathroomheater/zehnder.h @@ -97,7 +97,7 @@ class Zehnder : public Component, public Climate { remote_transmitter::RemoteTransmitterComponent *transmitter_ = nullptr; bool has_temperature_sensor_ = false; - bool transmit_temperature_(float* temp) { + bool transmit_temperature_(float *temp) { uint8_t level; if (*temp == 0) { level = 0; @@ -107,17 +107,21 @@ class Zehnder : public Component, public Climate { (TEMPERATURE_LEVELS - 1) / (MAX_TEMPERATURE - MIN_TEMPERATURE) + 1; + if (level > TEMPERATURE_LEVELS) { + level = TEMPERATURE_LEVELS; + } + *temp = (MAX_TEMPERATURE - MIN_TEMPERATURE) / (TEMPERATURE_LEVELS - 1) * - level + + (level - 1) + MIN_TEMPERATURE; } return this->transmit_level_(level); } bool transmit_level_(uint8_t level) { - if (level > 8) { + if (level > TEMPERATURE_LEVELS) { ESP_LOGE(TAG, "Unsupported heater level: %d. Ignoring command", level); return false; }