Skip to content

Commit

Permalink
Merge pull request #96 from echavet:echavet/issue95
Browse files Browse the repository at this point in the history
134 broke all my devices...
  • Loading branch information
echavet authored May 10, 2024
2 parents 778955e + 848a3ef commit f0179b4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
1 change: 1 addition & 0 deletions components/cn105/cn105.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR
void checkPowerAndModeSettings(heatpumpSettings& settings, bool updateCurrentSettings = true);
void checkFanSettings(heatpumpSettings& settings, bool updateCurrentSettings = true);
void checkVaneSettings(heatpumpSettings& settings, bool updateCurrentSettings = true);
void checkWideVaneSettings(heatpumpSettings& settings, bool updateCurrentSettings = true);
void updateExtraSelectComponents(heatpumpSettings& settings);

//void statusChanged();
Expand Down
57 changes: 45 additions & 12 deletions components/cn105/hp_readings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,14 @@ void CN105Climate::publishStateToHA(heatpumpSettings settings) {
checkFanSettings(settings);
}

if ((this->wantedSettings.vane == nullptr) && (this->wantedSettings.wideVane == nullptr)) { // to prevent overwriting a user demand
if (this->wantedSettings.vane == nullptr) { // to prevent overwriting a user demand
checkVaneSettings(settings);
}

if (this->wantedSettings.wideVane == nullptr) { // to prevent overwriting a user demand
checkWideVaneSettings(settings);
}

// HA Temp
if (this->wantedSettings.temperature == -1) { // to prevent overwriting a user demand
this->target_temperature = settings.temperature;
Expand Down Expand Up @@ -443,33 +447,62 @@ void CN105Climate::heatpumpUpdate(heatpumpSettings settings) {
this->publishStateToHA(settings);
}


void CN105Climate::checkVaneSettings(heatpumpSettings& settings, bool updateCurrentSettings) {
if (this->hasChanged(currentSettings.vane, settings.vane, "vane")) { // widevane setting change ?
ESP_LOGI(LOG_SETTINGS_TAG, "vane setting changed");

//this->debugSettings("settings", settings);

if (updateCurrentSettings) {
//ESP_LOGD(LOG_SETTINGS_TAG, "updating currentSetting with new value");
currentSettings.vane = settings.vane;
}

if (strcmp(settings.vane, "SWING") == 0) {
if ((currentSettings.wideVane != nullptr) && (strcmp(currentSettings.wideVane, "SWING") == 0)) {
this->swing_mode = climate::CLIMATE_SWING_BOTH;
} else {
this->swing_mode = climate::CLIMATE_SWING_VERTICAL;
}
} else {
if ((currentSettings.wideVane != nullptr) && (strcmp(currentSettings.wideVane, "SWING") == 0)) {
this->swing_mode = climate::CLIMATE_SWING_HORIZONTAL;
} else {
this->swing_mode = climate::CLIMATE_SWING_OFF;
}
}
ESP_LOGD(LOG_SETTINGS_TAG, "Swing mode is: %i", this->swing_mode);
}


updateExtraSelectComponents(settings);
}

void CN105Climate::checkWideVaneSettings(heatpumpSettings& settings, bool updateCurrentSettings) {

/* ******** HANDLE MITSUBISHI VANE CHANGES ********
* VANE_MAP[7] = {"AUTO", "1", "2", "3", "4", "5", "SWING"};
* WIDEVANE_MAP[7] = { "<<", "<", "|", ">", ">>", "<>", "SWING" }
*/

if (this->hasChanged(currentSettings.vane, settings.vane, "vane") || // vane setting change ?
this->hasChanged(currentSettings.wideVane, settings.wideVane, "wideVane")) { // widevane setting change ?
ESP_LOGI(TAG, "vane or widevane setting changed");
if (this->hasChanged(currentSettings.wideVane, settings.wideVane, "wideVane")) { // widevane setting change ?
ESP_LOGI(TAG, "widevane setting changed");
this->debugSettings("settings", settings);

// here I hope that the vane and widevane are always sent together
if (updateCurrentSettings) {
currentSettings.vane = settings.vane;
currentSettings.wideVane = settings.wideVane;
}
if (strcmp(settings.vane, "SWING") == 0) {
if (strcmp(settings.wideVane, "SWING") == 0) {

if (strcmp(settings.wideVane, "SWING") == 0) {
if ((currentSettings.vane != nullptr) && (strcmp(currentSettings.vane, "SWING") == 0)) {
this->swing_mode = climate::CLIMATE_SWING_BOTH;
} else {
this->swing_mode = climate::CLIMATE_SWING_VERTICAL;
this->swing_mode = climate::CLIMATE_SWING_HORIZONTAL;
}

} else {
if (strcmp(settings.wideVane, "SWING") == 0) {
this->swing_mode = climate::CLIMATE_SWING_HORIZONTAL;
if ((currentSettings.vane != nullptr) && (strcmp(currentSettings.vane, "SWING") == 0)) {
this->swing_mode = climate::CLIMATE_SWING_VERTICAL;
} else {
this->swing_mode = climate::CLIMATE_SWING_OFF;
}
Expand Down

0 comments on commit f0179b4

Please sign in to comment.