Optimistically report the newly set values when receiving an update, and support the simple kinda of ClimateActions.

This commit is contained in:
Phil Genera 2020-05-29 21:46:32 -04:00
parent 940b1c5929
commit 198dc5c052

View File

@ -102,6 +102,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) {
bool updated = false;
if (call.get_mode().has_value()){
this->mode = *call.get_mode();
switch (*call.get_mode()) {
case climate::CLIMATE_MODE_COOL:
hp->setModeSetting("COOL");
@ -142,13 +143,14 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) {
*call.get_target_temperature()
)
hp->setTemperature(*call.get_target_temperature());
this->target_temperature = *call.get_target_temperature();
updated = true;
}
//const char* FAN_MAP[6] = {"AUTO", "QUIET", "1", "2", "3", "4"};
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();
switch(*call.get_fan_mode()) {
case climate::CLIMATE_FAN_OFF:
hp->setPowerSetting("OFF");
@ -188,6 +190,7 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) {
ESP_LOGV(TAG, "control - requested swing mode is %s",
*call.get_swing_mode());
this->swing_mode = *call.get_swing_mode();
switch(*call.get_swing_mode()) {
case climate::CLIMATE_SWING_OFF:
hp->setVaneSetting("AUTO");
@ -203,6 +206,9 @@ void MitsubishiHeatPump::control(const climate::ClimateCall &call) {
}
}
ESP_LOGD(TAG, "control - Was HeatPump updated? %s", YESNO(updated));
// send the update back to esphome:
this->publish_state();
// and the heat pump:
hp->update();
}
@ -295,6 +301,20 @@ void MitsubishiHeatPump::hpSettingsChanged() {
ESP_LOGI(TAG, "Target temp is: %f", this->target_temperature);
/*
* Compute running state from mode & temperatures
*/
this->action = climate::CLIMATE_ACTION_OFF;
if (this->mode == climate::CLIMATE_MODE_HEAT) {
if (this->current_temperature < this->target_temperature) {
this->action = climate::CLIMATE_ACTION_HEATING;
}
} else if(this->mode == climate::CLIMATE_MODE_COOL) {
if (this->current_temperature > this->target_temperature) {
this->action = climate::CLIMATE_ACTION_COOLING;
}
}
/*
* ******** Publish state back to ESPHome. ********
*/