Skip to content

Commit

Permalink
Merge pull request #98 from echavet/echavet/issue74
Browse files Browse the repository at this point in the history
Echavet/issue74
  • Loading branch information
echavet authored May 11, 2024
2 parents 720a8e3 + 7493d4e commit ce19200
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions components/cn105/cn105.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}

Expand Down
5 changes: 4 additions & 1 deletion components/cn105/cn105.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion components/cn105/componentEntries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

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_);
}
1 change: 1 addition & 0 deletions components/cn105/cycle_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions components/cn105/hp_readings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,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) {
Expand All @@ -314,6 +319,9 @@ void CN105Climate::getDataFromResponsePacket() {
}

this->nbCompleteCycles_++;



break;

case 0x10:
Expand Down
27 changes: 14 additions & 13 deletions components/cn105/hp_writings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

0 comments on commit ce19200

Please sign in to comment.