From 4ca7d9575f53486573ee29d4ab88acc12e43cf79 Mon Sep 17 00:00:00 2001 From: Melik <10296053+melyux@users.noreply.github.com> Date: Fri, 3 Jan 2025 20:25:37 -0800 Subject: [PATCH 1/2] Publish new status and settings values only when they change --- components/cn105/Globals.h | 4 ++-- components/cn105/hp_readings.cpp | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/cn105/Globals.h b/components/cn105/Globals.h index b82f4ce..28e2a49 100644 --- a/components/cn105/Globals.h +++ b/components/cn105/Globals.h @@ -253,8 +253,8 @@ struct heatpumpStatus { float runtimeHours; bool operator==(const heatpumpStatus& other) const { - return roomTemperature == other.roomTemperature && - outsideAirTemperature == other.outsideAirTemperature && + return (std::isnan(roomTemperature) ? std::isnan(other.roomTemperature) : roomTemperature == other.roomTemperature) && + (std::isnan(outsideAirTemperature) ? std::isnan(other.outsideAirTemperature) : outsideAirTemperature == other.outsideAirTemperature) && operating == other.operating && //timers == other.timers && // Assurez-vous que l'opérateur == est également défini pour heatpumpTimers compressorFrequency == other.compressorFrequency && diff --git a/components/cn105/hp_readings.cpp b/components/cn105/hp_readings.cpp index 8e0415a..d59e600 100644 --- a/components/cn105/hp_readings.cpp +++ b/components/cn105/hp_readings.cpp @@ -157,13 +157,16 @@ void CN105Climate::getPowerFromResponsePacket() { ESP_LOGD("Decoder", "[Auto Mode Sub Mode : %s]", receivedSettings.auto_sub_mode); //this->heatpumpUpdate(receivedSettings); - if (this->Stage_sensor_ != nullptr) { + if (this->Stage_sensor_ != nullptr && (!this->currentSettings.stage || strcmp(receivedSettings.stage, this->currentSettings.stage) != 0)) { + this->currentSettings.stage = receivedSettings.stage; this->Stage_sensor_->publish_state(receivedSettings.stage); } - if (this->Sub_mode_sensor_ != nullptr) { + if (this->Sub_mode_sensor_ != nullptr && (!this->currentSettings.sub_mode || strcmp(receivedSettings.sub_mode, this->currentSettings.sub_mode) != 0)) { + this->currentSettings.sub_mode = receivedSettings.sub_mode; this->Sub_mode_sensor_->publish_state(receivedSettings.sub_mode); } - if (this->Auto_sub_mode_sensor_ != nullptr) { + if (this->Auto_sub_mode_sensor_ != nullptr && (!this->currentSettings.sub_mode || strcmp(receivedSettings.auto_sub_mode, this->currentSettings.auto_sub_mode) != 0)) { + this->currentSettings.auto_sub_mode = receivedSettings.auto_sub_mode; this->Auto_sub_mode_sensor_->publish_state(receivedSettings.auto_sub_mode); } } @@ -517,8 +520,8 @@ void CN105Climate::heatpumpUpdate(heatpumpSettings& settings) { if (this->currentSettings != settings) { ESP_LOGD(LOG_SETTINGS_TAG, "Settings changed, updating HA states"); + this->publishStateToHA(settings); } - this->publishStateToHA(settings); } void CN105Climate::checkVaneSettings(heatpumpSettings& settings, bool updateCurrentSettings) { From 8c8c238d4f14f0aa11ac0091a97e0f496787da35 Mon Sep 17 00:00:00 2001 From: Melik <10296053+melyux@users.noreply.github.com> Date: Fri, 3 Jan 2025 20:25:54 -0800 Subject: [PATCH 2/2] Fix typo causing missing power check --- components/cn105/hp_writings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/cn105/hp_writings.cpp b/components/cn105/hp_writings.cpp index 1302df9..8a28ffb 100644 --- a/components/cn105/hp_writings.cpp +++ b/components/cn105/hp_writings.cpp @@ -212,7 +212,7 @@ void CN105Climate::createPacket(uint8_t* packet) { void CN105Climate::publishWantedSettingsStateToHA() { - if ((this->wantedSettings.mode != nullptr) || (this->wantedSettings.mode != nullptr)) { + if ((this->wantedSettings.mode != nullptr) || (this->wantedSettings.power != nullptr)) { checkPowerAndModeSettings(this->wantedSettings, false); this->updateAction(); // update action info on HA climate component }