Merge pull request #143 from stewartadam/verify_serial

Mark component as failed if serial conflict is detected
This commit is contained in:
Geoff Davis 2024-06-23 14:04:51 -07:00 committed by GitHub
commit eebdff0d09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 11 deletions

View File

@ -47,15 +47,27 @@ MitsubishiHeatPump::MitsubishiHeatPump(
this->ping();
}
void MitsubishiHeatPump::check_logger_conflict_() {
bool MitsubishiHeatPump::verify_serial() {
if (!this->get_hw_serial_()) {
ESP_LOGCONFIG(
TAG,
"No HardwareSerial was provided. "
"Software serial ports are unsupported by this component."
);
return false;
}
#ifdef USE_LOGGER
if (this->get_hw_serial_() == logger::global_logger->get_hw_serial()) {
ESP_LOGW(TAG, " You're using the same serial port for logging"
" and the MitsubishiHeatPump component. Please disable"
" logging over the serial port by setting"
" logger:baud_rate to 0.");
return false;
}
#endif
// unless something went wrong, assume we have a valid serial configuration
return true;
}
void MitsubishiHeatPump::banner() {
@ -671,18 +683,13 @@ void MitsubishiHeatPump::setup() {
// This will be called by App.setup()
this->banner();
ESP_LOGCONFIG(TAG, "Setting up UART...");
if (!this->get_hw_serial_()) {
ESP_LOGCONFIG(
TAG,
"No HardwareSerial was provided. "
"Software serial ports are unsupported by this component."
);
if (!this->verify_serial()) {
this->mark_failed();
return;
}
this->check_logger_conflict_();
ESP_LOGCONFIG(TAG, "Intializing new HeatPump object.");
ESP_LOGCONFIG(TAG, "Initializing new HeatPump object.");
this->hp = new HeatPump();
this->current_temperature = NAN;
this->target_temperature = NAN;

View File

@ -142,8 +142,8 @@ class MitsubishiHeatPump : public esphome::PollingComponent, public esphome::cli
}
//Print a warning message if we're using the sole hardware UART on an
//ESP8266 or UART0 on ESP32
void check_logger_conflict_();
//ESP8266 or UART0 on ESP32, or if no serial was provided
bool verify_serial();
// various prefs to save mode-specific temperatures, akin to how the IR
// remote works.