Skip to content

Commit

Permalink
Merge branch 'main' into oat-patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
echavet authored Oct 7, 2024
2 parents 4b5e60f + c794b9c commit 07d0b51
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 33 deletions.
6 changes: 3 additions & 3 deletions components/cn105/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ struct wantedHeatpumpSettings : heatpumpSettings {
hasChanged = false;
hasBeenSent = false;
//nb_deffered_requests = 0;
//lastChange = 0;
//lastChange = 0;
}

wantedHeatpumpSettings& operator=(const wantedHeatpumpSettings& other) {
Expand All @@ -203,7 +203,7 @@ struct wantedHeatpumpSettings : heatpumpSettings {

wantedHeatpumpSettings& operator=(const heatpumpSettings& other) {
if (this != &other) { // self-assignment protection
heatpumpSettings::operator=(other); // Copie des membres de base
heatpumpSettings::operator=(other); // Copie des membres de base
}
return *this;
}
Expand Down Expand Up @@ -247,7 +247,7 @@ struct heatpumpStatus {
float outsideAirTemperature;
bool operating; // if true, the heatpump is operating to reach the desired temperature
heatpumpTimers timers;
int compressorFrequency;
float compressorFrequency;

bool operator==(const heatpumpStatus& other) const {
return roomTemperature == other.roomTemperature &&
Expand Down
8 changes: 4 additions & 4 deletions components/cn105/cn105.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CN105Climate::CN105Climate(uart::UARTComponent* uart) :

this->powerRequestWithoutResponses = 0; // power request is not supported by all heatpump #112

this->remote_temp_timeout_ = 4294967295; // uint32_t max
this->remote_temp_timeout_ = 4294967295; // uint32_t max
this->generateExtraComponents();
this->loopCycle.init();
this->wantedSettings.resetSettings();
Expand Down Expand Up @@ -71,7 +71,7 @@ void CN105Climate::set_remote_temp_timeout(uint32_t timeout) {
if (timeout == 4294967295) {
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 %lu", timeout);
//ESP_LOGI(LOG_ACTION_EVT_TAG, "set_remote_temp_timeout is set to %lu", timeout);
log_info_uint32(LOG_ACTION_EVT_TAG, "set_remote_temp_timeout is set to ", timeout);

this->pingExternalTemperature();
Expand All @@ -84,7 +84,7 @@ void CN105Climate::set_debounce_delay(uint32_t delay) {
log_info_uint32(LOG_ACTION_EVT_TAG, "set_debounce_delay is set to ", delay);
}

int CN105Climate::get_compressor_frequency() {
float CN105Climate::get_compressor_frequency() {
return currentStatus.compressorFrequency;
}
bool CN105Climate::is_operating() {
Expand Down Expand Up @@ -173,7 +173,7 @@ bool CN105Climate::isHeatpumpConnectionActive() {
// if (lrTimeMs > MAX_DELAY_RESPONSE_FACTOR * this->update_interval_) {
// ESP_LOGV(TAG, "Heatpump has not replied for %ld s", lrTimeMs / 1000);
// ESP_LOGV(TAG, "We think Heatpump is not connected anymore..");
// this->disconnectUART();
// this->disconnectUART();
// }

return (lrTimeMs < MAX_DELAY_RESPONSE_FACTOR * this->update_interval_);
Expand Down
4 changes: 2 additions & 2 deletions components/cn105/cn105.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR
sensor::Sensor* outside_air_temperature_sensor_ =
nullptr; // Outside air temperature

// sensor to monitor heatpump connection time
// sensor to monitor heatpump connection time
uptime::HpUpTimeConnectionSensor* hp_uptime_connection_sensor_ = nullptr;

int get_compressor_frequency();
float get_compressor_frequency();
bool is_operating();

// checks if the field has changed
Expand Down
47 changes: 30 additions & 17 deletions components/cn105/hp_readings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void CN105Climate::processDataPacket() {

if (this->checkSum()) {
// checkPoint of a heatpump response
this->lastResponseMs = CUSTOM_MILLIS; //esphome::CUSTOM_MILLIS;
this->lastResponseMs = CUSTOM_MILLIS; //esphome::CUSTOM_MILLIS;

// processing the specific command
processCommand();
Expand Down Expand Up @@ -172,7 +172,7 @@ void CN105Climate::getSettingsFromResponsePacket() {
heatpumpSettings receivedSettings{};
ESP_LOGD("Decoder", "[0x02 is settings]");
//02 00 00 01 08 0A 00 07 00 00 03 AA 00 00 00 00 94
//this->last_received_packet_sensor->publish_state("0x62-> 0x02: Data -> Settings");
//this->last_received_packet_sensor->publish_state("0x62-> 0x02: Data -> Settings");
receivedSettings.connected = true; // we're here so we're connected (actually not used property)
receivedSettings.power = lookupByteMapValue(POWER_MAP, POWER, 2, data[3], "power reading");
receivedSettings.iSee = data[4] > 0x08 ? true : false;
Expand Down Expand Up @@ -228,6 +228,7 @@ void CN105Climate::getRoomTemperatureFromResponsePacket() {

//ESP_LOGD("Decoder", "[0x03 room temperature]");
//this->last_received_packet_sensor->publish_state("0x62-> 0x03: Data -> Room temperature");

// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// FC 62 01 30 10 03 00 00 0E 00 94 B0 B0 FE 42 00 01 0A 64 00 00 A9
// RT OT RT SP ?? ?? ?? CT CT
Expand All @@ -236,11 +237,12 @@ void CN105Climate::getRoomTemperatureFromResponsePacket() {
// SP = room setpoint temperature?
// CT = increasing counter (unknown function)

if (data[5] != 0x00)
receivedStatus.outsideAirTemperature = (float)(data[5] - 128) / 2;
else
receivedStatus.outsideAirTemperature = -1;

if (data[5] != 0x00) {
receivedStatus.outsideAirTemperature = (float)(data[5] - 128) / 2;
} else {
receivedStatus.outsideAirTemperature = -1;
}

if (data[6] != 0x00) {
int temp = data[6];
temp -= 128;
Expand All @@ -256,18 +258,29 @@ void CN105Climate::getRoomTemperatureFromResponsePacket() {
receivedStatus.operating = currentStatus.operating;
receivedStatus.compressorFrequency = currentStatus.compressorFrequency;
this->statusChanged(receivedStatus);

}

void CN105Climate::getOperatingAndCompressorFreqFromResponsePacket() {
//FC 62 01 30 10 06 00 00 1A 01 00 00 00 00 00 00 00 00 00 00 00 3C
//MSZ-RW25VGHZ-SC1 / MUZ-RW25VGHZ-SC1
//FC 62 01 30 10 06 00 00 00 01 00 08 05 50 00 00 42 00 00 00 00 B7
// OP CF CF ?? CT ??
// OP = operating status (1 = compressor running, 0 = standby)
// CF = compressor frequency in 16-bit integer, 1 decimal accuracy
// (frequency in float = value / 10)
// CT = slowly increasing counter, unknown function
// ?? = unknown bytes that appear to have a fixed/constant value
heatpumpStatus receivedStatus{};
ESP_LOGD("Decoder", "[0x06 is status]");
//this->last_received_packet_sensor->publish_state("0x62-> 0x06: Data -> Heatpump Status");

// reset counter (because a reply indicates it is connected)
this->nonResponseCounter = 0;
receivedStatus.operating = data[4];
receivedStatus.compressorFrequency = data[3];
if (data[5] || data[6])
receivedStatus.compressorFrequency = (float)((data[5] << 8) | data[6]) / 10;
else
receivedStatus.compressorFrequency = (float)data[3];

// no change with this packet to roomTemperature
receivedStatus.roomTemperature = currentStatus.roomTemperature;
Expand Down Expand Up @@ -296,7 +309,7 @@ void CN105Climate::getDataFromResponsePacket() {
case 0x02: /* setting information */
ESP_LOGD(LOG_CYCLE_TAG, "2b: Receiving settings response");
this->getSettingsFromResponsePacket();
// next step is to get the room temperature case 0x03
// next step is to get the room temperature case 0x03
ESP_LOGD(LOG_CYCLE_TAG, "3a: Sending room °C request (0x03)");
this->buildAndSendRequestPacket(RQST_PKT_ROOM_TEMP);
break;
Expand All @@ -305,7 +318,7 @@ void CN105Climate::getDataFromResponsePacket() {
/* room temperature reading */
ESP_LOGD(LOG_CYCLE_TAG, "3b: Receiving room °C response");
this->getRoomTemperatureFromResponsePacket();
// next step is to get the heatpump status (operating and compressor frequency) case 0x06
// next step is to get the heatpump status (operating and compressor frequency) case 0x06
ESP_LOGD(LOG_CYCLE_TAG, "4a: Sending status request (0x06)");
this->buildAndSendRequestPacket(RQST_PKT_STATUS);
break;
Expand Down Expand Up @@ -345,7 +358,7 @@ void CN105Climate::getDataFromResponsePacket() {
/* Power */
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
//FC 62 01 30 10 09 00 00 00 02 02 00 00 00 00 00 00 00 00 00 00 50
// reset the powerRequestWithoutResponses to 0 as we had a response
this->powerRequestWithoutResponses = 0;

Expand Down Expand Up @@ -401,9 +414,9 @@ void CN105Climate::processCommand() {
ESP_LOGI(TAG, "--> Heatpump did reply: connection success! <--");
//this->isHeatpumpConnected_ = true;
this->setHeatpumpConnected(true);
// let's say that the last complete cycle was over now
// let's say that the last complete cycle was over now
this->loopCycle.lastCompleteCycleMs = CUSTOM_MILLIS;
this->currentSettings.resetSettings(); // each time we connect, we need to reset current setting to force a complete sync with ha component state and receievdSettings
this->currentSettings.resetSettings(); // each time we connect, we need to reset current setting to force a complete sync with ha component state and receievdSettings
break;
default:
break;
Expand All @@ -424,7 +437,7 @@ void CN105Climate::statusChanged(heatpumpStatus status) {
this->currentStatus.outsideAirTemperature = status.outsideAirTemperature;
this->current_temperature = currentStatus.roomTemperature;

this->updateAction(); // update action info on HA climate component
this->updateAction(); // update action info on HA climate component
this->publish_state();

if (this->compressor_frequency_sensor_ != nullptr) {
Expand All @@ -440,7 +453,7 @@ void CN105Climate::statusChanged(heatpumpStatus status) {

void CN105Climate::publishStateToHA(heatpumpSettings settings) {

if ((this->wantedSettings.mode == nullptr) && (this->wantedSettings.power == nullptr)) { // to prevent overwriting a user demand
if ((this->wantedSettings.mode == nullptr) && (this->wantedSettings.power == nullptr)) { // to prevent overwriting a user demand
checkPowerAndModeSettings(settings);
}

Expand Down Expand Up @@ -474,7 +487,7 @@ void CN105Climate::publishStateToHA(heatpumpSettings settings) {


void CN105Climate::heatpumpUpdate(heatpumpSettings settings) {
// settings correponds to current settings
// settings correponds to current settings
ESP_LOGV(LOG_SETTINGS_TAG, "Settings received");

this->debugSettings("current", this->currentSettings);
Expand Down
8 changes: 4 additions & 4 deletions components/cn105/hp_writings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void CN105Climate::sendFirstConnectionPacket() {

// ESP_LOGD(TAG, "t°: %f", currentStatus.roomTemperature);
// ESP_LOGD(TAG, "operating: %d", currentStatus.operating);
// ESP_LOGD(TAG, "compressor freq: %d", currentStatus.compressorFrequency);
// ESP_LOGD(TAG, "compressor freq: %f", currentStatus.compressorFrequency);

// this->updateAction();
// this->publish_state();
Expand Down Expand Up @@ -275,10 +275,10 @@ void CN105Climate::sendWantedSettings() {
#ifdef USE_ESP32
std::lock_guard<std::mutex> guard(wantedSettingsMutex);
this->sendWantedSettingsDelegate();
#else
#else
this->emulateMutex("WRITE_SETTINGS", std::bind(&CN105Climate::sendWantedSettingsDelegate, this));

#endif
#endif

} else {
ESP_LOGD(TAG, "will sendWantedSettings later because we've sent one too recently...");
Expand Down Expand Up @@ -379,4 +379,4 @@ void CN105Climate::sendRemoteTemperature() {
this->pingExternalTemperature();


}
}
6 changes: 3 additions & 3 deletions components/cn105/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ void CN105Climate::debugSettings(const char* settingName, heatpumpSettings setti

void CN105Climate::debugStatus(const char* statusName, heatpumpStatus status) {
#ifdef USE_ESP32
ESP_LOGI(LOG_STATUS_TAG, "[%s]-> [room C°: %.1f, operating: %s, compressor freq: %2d Hz]",
ESP_LOGI(LOG_STATUS_TAG, "[%s]-> [room C°: %.1f, operating: %s, compressor freq: %.1f Hz]",
statusName,
status.roomTemperature,
status.operating ? "YES" : "NO ",
status.compressorFrequency);
#else
ESP_LOGI(LOG_STATUS_TAG, "[%-*s]-> [room C°: %.1f, operating: %-*s, compressor freq: %2d Hz]",
ESP_LOGI(LOG_STATUS_TAG, "[%-*s]-> [room C°: %.1f, operating: %-*s, compressor freq: %.1f Hz]",
15, statusName,
status.roomTemperature,
3, status.operating ? "YES" : "NO ",
Expand Down Expand Up @@ -280,7 +280,7 @@ void CN105Climate::logDelegate() {
} else {
ESP_LOGI("testMutex", "Mutex est déjà verrouillé");
}
#endif
#endif
}

void CN105Climate::testCase1() {
Expand Down

0 comments on commit 07d0b51

Please sign in to comment.