From 25326fa6b92bfabace1a344b201cea7384361b06 Mon Sep 17 00:00:00 2001 From: Sammy1Am <467704+Sammy1Am@users.noreply.github.com> Date: Thu, 15 Aug 2024 04:10:24 +0000 Subject: [PATCH] Add some sanity checking when set to Internal temperature source --- .../mitsubishi_itp/mitsubishi_itp.cpp | 30 +++++++++++-------- .../mitsubishi_itp/mitsubishi_itp.h | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/esphome/components/mitsubishi_itp/mitsubishi_itp.cpp b/esphome/components/mitsubishi_itp/mitsubishi_itp.cpp index c7ab8a0ad4..3b4b9f305f 100644 --- a/esphome/components/mitsubishi_itp/mitsubishi_itp.cpp +++ b/esphome/components/mitsubishi_itp/mitsubishi_itp.cpp @@ -51,19 +51,25 @@ void MitsubishiUART::loop() { if (ts_bridge_) ts_bridge_->loop(); - // If it's been too long since we received a temperature update (and we're not set to Internal) - if (((millis() - last_received_temperature_) > TEMPERATURE_SOURCE_TIMEOUT_MS) && - current_temperature_source_ != TEMPERATURE_SOURCE_INTERNAL && !temperature_source_timeout_) { - ESP_LOGW(TAG, "No temperature received from %s for %lu milliseconds, reverting to Internal source", - current_temperature_source_.c_str(), (unsigned long) TEMPERATURE_SOURCE_TIMEOUT_MS); - // Let listeners know we've changed to the Internal temperature source (but do not change - // currentTemperatureSource) - for (auto *listener : listeners_) { - listener->temperature_source_change(TEMPERATURE_SOURCE_INTERNAL); + if ((millis() - last_received_temperature_) > TEMPERATURE_SOURCE_TIMEOUT_MS) { + if (current_temperature_source_.empty() || current_temperature_source_ != TEMPERATURE_SOURCE_INTERNAL) { + ESP_LOGD(TAG, "Reminding heat pump to use internal temperature sensor"); + // Check to make sure a temperature source is set-- if not, set to internal for sanity reasons + IFACTIVE(this->select_temperature_source(TEMPERATURE_SOURCE_INTERNAL);) + last_received_temperature_ = millis(); // Count this as "receiving" the internal temperature + } else if (!temperature_source_timeout_) { + // If it's been too long since we received a temperature update (and we're not set to Internal) + ESP_LOGW(TAG, "No temperature received from %s for %lu milliseconds, reverting to Internal source", + current_temperature_source_.c_str(), (unsigned long) TEMPERATURE_SOURCE_TIMEOUT_MS); + // Let listeners know we've changed to the Internal temperature source (but do not change + // currentTemperatureSource) + for (auto *listener : listeners_) { + listener->temperature_source_change(TEMPERATURE_SOURCE_INTERNAL); + } + temperature_source_timeout_ = true; + // Send a packet to the heat pump to tell it to switch to internal temperature sensing + IFACTIVE(hp_bridge_.send_packet(RemoteTemperatureSetRequestPacket().use_internal_temperature());) } - temperature_source_timeout_ = true; - // Send a packet to the heat pump to tell it to switch to internal temperature sensing - IFACTIVE(hp_bridge_.send_packet(RemoteTemperatureSetRequestPacket().use_internal_temperature());) } } diff --git a/esphome/components/mitsubishi_itp/mitsubishi_itp.h b/esphome/components/mitsubishi_itp/mitsubishi_itp.h index 996dacf051..d4ef53af01 100644 --- a/esphome/components/mitsubishi_itp/mitsubishi_itp.h +++ b/esphome/components/mitsubishi_itp/mitsubishi_itp.h @@ -165,7 +165,7 @@ class MitsubishiUART : public PollingComponent, public climate::Climate, public } // Temperature select extras - std::string current_temperature_source_ = TEMPERATURE_SOURCE_INTERNAL; + std::string current_temperature_source_; uint32_t last_received_temperature_ = millis(); bool temperature_source_timeout_ = false; // Has the current source timed out?