Skip to content

Commit

Permalink
Update espmhp.cpp
Browse files Browse the repository at this point in the history
Reverted back to original and simply commenting out line causing issues.
  • Loading branch information
markalston committed Nov 7, 2023
1 parent 20a38ba commit 7d69ca1
Showing 1 changed file with 47 additions and 73 deletions.
120 changes: 47 additions & 73 deletions components/mitsubishi_heatpump/espmhp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,149 +103,123 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) {
bool updated = false;
bool has_mode = call.get_mode().has_value();
bool has_temp = call.get_target_temperature().has_value();
bool has_fan = call.get_fan_mode().has_value();
bool has_swing = call.get_swing_mode().has_value();

if (has_mode){
ESP_LOGV(TAG, "Has Mode");
} else {
ESP_LOGV(TAG, "Doesn't Have Mode");
}
if (has_temp){
ESP_LOGV(TAG, "Has Temp");
} else {
ESP_LOGV(TAG, "Doesn't Have Temp");
}
if (has_fan){
ESP_LOGV(TAG, "Has Fan");
} else {
ESP_LOGV(TAG, "Doesn't Have Fan");
}
if (has_swing){
ESP_LOGV(TAG, "Has Swing");
} else {
ESP_LOGV(TAG, "Doesn't Have Swing");
}

if (has_mode){
this->mode = *call.get_mode();
switch (this->mode) {
case climate::CLIMATE_MODE_COOL:
hp->setModeSetting("COOL");
hp->setPowerSetting("ON");
}
switch (this->mode) {
case climate::CLIMATE_MODE_COOL:
hp->setModeSetting("COOL");
hp->setPowerSetting("ON");

if (has_mode){
if (cool_setpoint.has_value() && !has_temp) {
hp->setTemperature(cool_setpoint.value());
this->target_temperature = cool_setpoint.value();
}
this->action = climate::CLIMATE_ACTION_IDLE;
updated = true;
break;
case climate::CLIMATE_MODE_HEAT:
hp->setModeSetting("HEAT");
hp->setPowerSetting("ON");

}
break;
case climate::CLIMATE_MODE_HEAT:
hp->setModeSetting("HEAT");
hp->setPowerSetting("ON");
if (has_mode){
if (heat_setpoint.has_value() && !has_temp) {
hp->setTemperature(heat_setpoint.value());
this->target_temperature = heat_setpoint.value();
}
this->action = climate::CLIMATE_ACTION_IDLE;
updated = true;
break;
case climate::CLIMATE_MODE_DRY:
hp->setModeSetting("DRY");
hp->setPowerSetting("ON");

updated = true;
}
break;
case climate::CLIMATE_MODE_DRY:
hp->setModeSetting("DRY");
hp->setPowerSetting("ON");
if (has_mode){
this->action = climate::CLIMATE_ACTION_DRYING;
updated = true;
break;
case climate::CLIMATE_MODE_HEAT_COOL:
hp->setModeSetting("AUTO");
hp->setPowerSetting("ON");

updated = true;
}
break;
case climate::CLIMATE_MODE_HEAT_COOL:
hp->setModeSetting("AUTO");
hp->setPowerSetting("ON");
if (has_mode){
if (auto_setpoint.has_value() && !has_temp) {
hp->setTemperature(auto_setpoint.value());
this->target_temperature = auto_setpoint.value();
}
this->action = climate::CLIMATE_ACTION_IDLE;
updated = true;
break;
case climate::CLIMATE_MODE_FAN_ONLY:
hp->setModeSetting("FAN");
hp->setPowerSetting("ON");
}
updated = true;
break;
case climate::CLIMATE_MODE_FAN_ONLY:
hp->setModeSetting("FAN");
hp->setPowerSetting("ON");
if (has_mode){
this->action = climate::CLIMATE_ACTION_FAN;
updated = true;
break;
case climate::CLIMATE_MODE_OFF:
default:
}
break;
case climate::CLIMATE_MODE_OFF:
default:
if (has_mode){
hp->setPowerSetting("OFF");
this->action = climate::CLIMATE_ACTION_OFF;
updated = true;
break;
}
}
break;
}

if (has_temp){
ESP_LOGV(TAG, "control - Sending target temp: %.1f",
ESP_LOGV(
"control", "Sending target temp: %.1f",
*call.get_target_temperature()
);
hp->setTemperature(*call.get_target_temperature());
this->target_temperature = *call.get_target_temperature();
updated = true;
}

ESP_LOGV(TAG,"About to enter fan control block");
//const char* FAN_MAP[6] = {"AUTO", "QUIET", "1", "2", "3", "4"};
if (has_fan) {
//ESP_LOGV(TAG, "control - Requested fan mode is %s", *call.get_fan_mode());
ESP_LOGV(TAG,"Inside fan control block");

if (call.get_fan_mode().has_value()) {
// ESP_LOGV("control", "Requested fan mode is %s", *call.get_fan_mode());
this->fan_mode = *call.get_fan_mode();
ESP_LOGV(TAG,"Got fan mode");

switch (*call.get_fan_mode()) {
switch(*call.get_fan_mode()) {
case climate::CLIMATE_FAN_OFF:
ESP_LOGV(TAG,"Setting Fan Off");
hp->setPowerSetting("OFF");
updated = true;
break;
case climate::CLIMATE_FAN_DIFFUSE:
ESP_LOGV(TAG,"Setting Fan Diffuse");
hp->setFanSpeed("QUIET");
updated = true;
break;
case climate::CLIMATE_FAN_LOW:
ESP_LOGV(TAG,"Setting Fan Low");
hp->setFanSpeed("1");
updated = true;
break;
case climate::CLIMATE_FAN_MEDIUM:
ESP_LOGV(TAG,"Setting Fan Medium");
hp->setFanSpeed("2");
updated = true;
break;
case climate::CLIMATE_FAN_MIDDLE:
ESP_LOGV(TAG,"Setting Fan Middle");
hp->setFanSpeed("3");
updated = true;
break;
case climate::CLIMATE_FAN_HIGH:
ESP_LOGV(TAG,"Setting Fan High");
hp->setFanSpeed("4");
updated = true;
break;
case climate::CLIMATE_FAN_ON:
case climate::CLIMATE_FAN_AUTO:
default:
ESP_LOGV(TAG,"Setting Fan Auto");
hp->setFanSpeed("AUTO");
updated = true;
break;
}
}

//const char* VANE_MAP[7] = {"AUTO", "1", "2", "3", "4", "5", "SWING"};
if (has_swing) {
if (call.get_swing_mode().has_value()) {
ESP_LOGV(TAG, "control - requested swing mode is %s",
*call.get_swing_mode());

Expand All @@ -269,7 +243,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) {
// send the update back to esphome:
this->publish_state();
// and the heat pump:
// hp->update();
hp->update();
}

void MitsubishiHeatPump::hpSettingsChanged() {
Expand Down

0 comments on commit 7d69ca1

Please sign in to comment.