From 091c5757d12028fc773f6ee823b3ef6e4ed041a2 Mon Sep 17 00:00:00 2001 From: Josh Benner Date: Fri, 9 Jun 2023 20:49:44 -0400 Subject: [PATCH] Re-read & publish states immediately after control commands --- .../daikin_s21/climate/daikin_s21_climate.cpp | 16 ++++++++++++++-- components/daikin_s21/s21.cpp | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/components/daikin_s21/climate/daikin_s21_climate.cpp b/components/daikin_s21/climate/daikin_s21_climate.cpp index 87348b5..e57f0e3 100644 --- a/components/daikin_s21/climate/daikin_s21_climate.cpp +++ b/components/daikin_s21/climate/daikin_s21_climate.cpp @@ -102,10 +102,14 @@ float DaikinS21Climate::get_room_temp_offset() { return s21_val - room_val; } +float nearest_step(float temp) { + return std::round(temp / SETPOINT_STEP) * SETPOINT_STEP; +} + // What setpoint should be sent to s21, acconting for external room sensor. float DaikinS21Climate::calc_s21_setpoint(float target) { float offset_target = target + this->get_room_temp_offset(); - return std::round(offset_target / SETPOINT_STEP) * SETPOINT_STEP; + return nearest_step(offset_target); } // How far from desired setpoint is the current S21 setpoint? @@ -347,7 +351,8 @@ void DaikinS21Climate::control(const climate::ClimateCall &call) { set_basic = true; } if (call.get_target_temperature().has_value()) { - this->target_temperature = call.get_target_temperature().value(); + this->target_temperature = + nearest_step(call.get_target_temperature().value()); set_basic = true; } if (call.get_custom_fan_mode().has_value()) { @@ -364,11 +369,18 @@ void DaikinS21Climate::control(const climate::ClimateCall &call) { this->s21->set_swing_settings(this->e2d_swing_v(swing_mode), this->e2d_swing_h(swing_mode)); } + + this->update(); } void DaikinS21Climate::set_s21_climate() { this->expected_s21_setpoint = this->calc_s21_setpoint(this->target_temperature); + ESP_LOGI(TAG, "Controlling S21 climate:"); + ESP_LOGI(TAG, " Mode: %s", climate::climate_mode_to_string(this->mode)); + ESP_LOGI(TAG, " Setpoint: %.1f (s21: %.1f)", this->target_temperature, + this->expected_s21_setpoint); + ESP_LOGI(TAG, " Fan: %s", this->custom_fan_mode.value().c_str()); this->s21->set_daikin_climate_settings( this->mode != climate::CLIMATE_MODE_OFF, this->e2d_climate_mode(this->mode), this->expected_s21_setpoint, diff --git a/components/daikin_s21/s21.cpp b/components/daikin_s21/s21.cpp index ddfc9ec..45d6e56 100644 --- a/components/daikin_s21/s21.cpp +++ b/components/daikin_s21/s21.cpp @@ -415,6 +415,8 @@ void DaikinS21::set_daikin_climate_settings(bool power_on, ESP_LOGD(TAG, "Sending basic climate CMD (D1): %s", str_repr(cmd).c_str()); if (!this->send_cmd({'D', '1'}, cmd)) { ESP_LOGW(TAG, "Failed basic climate CMD"); + } else { + this->update(); } } @@ -426,6 +428,8 @@ void DaikinS21::set_swing_settings(bool swing_v, bool swing_h) { ESP_LOGD(TAG, "Sending swing CMD (D5): %s", str_repr(cmd).c_str()); if (!this->send_cmd({'D', '5'}, cmd)) { ESP_LOGW(TAG, "Failed swing CMD"); + } else { + this->update(); } }