Merge pull request #7 from pgenera/optimistic-changes

Optimistically report changes to esphome

Closes GH-4, GH-6
This commit is contained in:
Geoff Davis
2020-06-02 19:08:28 -07:00
committed by GitHub

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,10 @@ 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 +302,25 @@ void MitsubishiHeatPump::hpSettingsChanged() {
ESP_LOGI(TAG, "Target temp is: %f", this->target_temperature);
/*
* Compute running state from mode & temperatures
*/
switch (this->mode) {
case climate::CLIMATE_MODE_HEAT:
if (this->current_temperature < this->target_temperature) {
this->action = climate::CLIMATE_ACTION_HEATING;
}
break;
case climate::CLIMATE_MODE_COOL:
case climate::CLIMATE_MODE_DRY:
if (this->current_temperature > this->target_temperature) {
this->action = climate::CLIMATE_ACTION_COOLING;
}
break;
default:
this->action = climate::CLIMATE_ACTION_OFF;
}
/*
* ******** Publish state back to ESPHome. ********
*/