From 0276f693765161216ec400a69bfbef7e316eb0bf Mon Sep 17 00:00:00 2001 From: Eric Chavet Date: Sat, 11 May 2024 16:04:19 +0200 Subject: [PATCH] External temperature updates don't always persist on the unit Fixes #74 --- components/cn105/cn105.cpp | 4 ++-- components/cn105/cn105.h | 5 ++++- components/cn105/componentEntries.cpp | 8 +++++++- components/cn105/cycle_management.cpp | 1 + components/cn105/hp_readings.cpp | 8 ++++++++ components/cn105/hp_writings.cpp | 27 ++++++++++++++------------- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/components/cn105/cn105.cpp b/components/cn105/cn105.cpp index 1c2f602..1362ed4 100644 --- a/components/cn105/cn105.cpp +++ b/components/cn105/cn105.cpp @@ -57,7 +57,7 @@ void CN105Climate::set_tx_rx_pins(uint8_t tx_pin, uint8_t rx_pin) { } -void CN105Climate::setExternalTemperatureCheckout() { +void CN105Climate::pingExternalTemperature() { this->set_timeout(SHEDULER_REMOTE_TEMP_TIMEOUT, this->remote_temp_timeout_, [this]() { ESP_LOGW(LOG_ACTION_EVT_TAG, "Remote temperature timeout occured, fall back to internal temperature!"); this->set_remote_temperature(0); @@ -70,7 +70,7 @@ void CN105Climate::set_remote_temp_timeout(uint32_t timeout) { ESP_LOGI(LOG_ACTION_EVT_TAG, "set_remote_temp_timeout is set to never."); } else { ESP_LOGI(LOG_ACTION_EVT_TAG, "set_remote_temp_timeout is set to %d", timeout); - this->setExternalTemperatureCheckout(); + this->pingExternalTemperature(); } } diff --git a/components/cn105/cn105.h b/components/cn105/cn105.h index 9d1524a..5c9e82f 100644 --- a/components/cn105/cn105.h +++ b/components/cn105/cn105.h @@ -88,13 +88,14 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR // Use the temperature from an external sensor. Use // set_remote_temp(0) to switch back to the internal sensor. void set_remote_temperature(float); + void sendRemoteTemperature(); void set_remote_temp_timeout(uint32_t timeout); void set_debounce_delay(uint32_t delay); // this is the ping or heartbeat of the setRemotetemperature for timeout management - void setExternalTemperatureCheckout(); + void pingExternalTemperature(); uint32_t get_update_interval() const; void set_update_interval(uint32_t update_interval); @@ -118,6 +119,8 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR bool isUARTConnected_ = false; bool isHeatpumpConnected_ = false; + bool shouldSendExternalTemperature_ = false; + float remoteTemperature_ = 0; unsigned long nbCompleteCycles_ = 0; unsigned long nbCycles_ = 0; diff --git a/components/cn105/componentEntries.cpp b/components/cn105/componentEntries.cpp index 2242044..def4164 100644 --- a/components/cn105/componentEntries.cpp +++ b/components/cn105/componentEntries.cpp @@ -59,4 +59,10 @@ void CN105Climate::set_update_interval(uint32_t update_interval) { ESP_LOGD(TAG, "Setting update interval to %d", update_interval); this->update_interval_ = update_interval; this->autoUpdate = (update_interval != 0); -} \ No newline at end of file +} + +void CN105Climate::set_remote_temperature(float setting) { + this->shouldSendExternalTemperature_ = true; + this->remoteTemperature_ = setting; + ESP_LOGD(LOG_SETTINGS_TAG, "setting remote temperature to %f", this->remoteTemperature_); +} diff --git a/components/cn105/cycle_management.cpp b/components/cn105/cycle_management.cpp index 9054add..3080920 100644 --- a/components/cn105/cycle_management.cpp +++ b/components/cn105/cycle_management.cpp @@ -50,6 +50,7 @@ void cycleManagement::cycleEnded(bool timedOut) { ESP_LOGI(LOG_CYCLE_TAG, "6: Cycle ended in %.1f seconds (with timeout?: %s)", (lastCompleteCycleMs - lastCycleStartMs) / 1000.0, timedOut ? "YES" : " NO"); + } bool cycleManagement::hasUpdateIntervalPassed(unsigned int update_interval) { diff --git a/components/cn105/hp_readings.cpp b/components/cn105/hp_readings.cpp index 1e6a567..8325116 100644 --- a/components/cn105/hp_readings.cpp +++ b/components/cn105/hp_readings.cpp @@ -303,6 +303,11 @@ void CN105Climate::getDataFromResponsePacket() { ESP_LOGD(LOG_CYCLE_TAG, "5b: Receiving Power/Standby response"); this->getPowerFromResponsePacket(); //FC 62 01 30 10 09 00 00 00 02 02 00 00 00 00 00 00 00 00 00 00 50 + + if (this->shouldSendExternalTemperature_) { + this->sendRemoteTemperature(); + } + this->loopCycle.cycleEnded(); if (this->hp_uptime_connection_sensor_ != nullptr) { @@ -312,6 +317,9 @@ void CN105Climate::getDataFromResponsePacket() { } this->nbCompleteCycles_++; + + + break; case 0x10: diff --git a/components/cn105/hp_writings.cpp b/components/cn105/hp_writings.cpp index 5d3d3da..0a62ee0 100644 --- a/components/cn105/hp_writings.cpp +++ b/components/cn105/hp_writings.cpp @@ -350,20 +350,25 @@ void CN105Climate::createInfoPacket(uint8_t* packet, uint8_t packetType) { uint8_t chkSum = checkSum(packet, 21); packet[21] = chkSum; } -void CN105Climate::set_remote_temperature(float setting) { + + +void CN105Climate::sendRemoteTemperature() { + + this->shouldSendExternalTemperature_ = false; + uint8_t packet[PACKET_LEN] = {}; prepareSetPacket(packet, PACKET_LEN); packet[5] = 0x07; - if (setting > 0) { + if (this->remoteTemperature_ > 0) { packet[6] = 0x01; - setting = setting * 2; - setting = round(setting); - setting = setting / 2; - float temp1 = 3 + ((setting - 10) * 2); + this->remoteTemperature_ = this->remoteTemperature_ * 2; + this->remoteTemperature_ = round(this->remoteTemperature_); + this->remoteTemperature_ = this->remoteTemperature_ / 2; + float temp1 = 3 + ((this->remoteTemperature_ - 10) * 2); packet[7] = (int)temp1; - float temp2 = (setting * 2) + 128; + float temp2 = (this->remoteTemperature_ * 2) + 128; packet[8] = (int)temp2; } else { packet[6] = 0x00; @@ -376,11 +381,7 @@ void CN105Climate::set_remote_temperature(float setting) { writePacket(packet, PACKET_LEN); // this resets the timeout - this->setExternalTemperatureCheckout(); + this->pingExternalTemperature(); + - // optimistic - // this->currentStatus.roomTemperature = setting; - // this->current_temperature = this->currentStatus.roomTemperature; - // forces the UI component sync - // this->publish_state(); } \ No newline at end of file