Add some sanity checking when set to Internal temperature source

This commit is contained in:
Sammy1Am 2024-08-15 04:10:24 +00:00
parent 0bb5419851
commit 25326fa6b9
2 changed files with 19 additions and 13 deletions

View file

@ -51,9 +51,14 @@ void MitsubishiUART::loop() {
if (ts_bridge_)
ts_bridge_->loop();
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)
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
@ -66,6 +71,7 @@ void MitsubishiUART::loop() {
IFACTIVE(hp_bridge_.send_packet(RemoteTemperatureSetRequestPacket().use_internal_temperature());)
}
}
}
void MitsubishiUART::dump_config() {
if (capabilities_cache_.has_value()) {

View file

@ -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?