mirror of
https://github.com/esphome/esphome.git
synced 2025-11-17 07:15:48 +00:00
Add reset_reason text sensor to debug component (#3814)
This commit is contained in:
committed by
GitHub
parent
2f62426f09
commit
392dc8b0db
@@ -38,6 +38,7 @@ static uint32_t get_free_heap() {
|
||||
|
||||
void DebugComponent::dump_config() {
|
||||
std::string device_info;
|
||||
std::string reset_reason;
|
||||
device_info.reserve(256);
|
||||
|
||||
#ifndef ESPHOME_LOG_HAS_DEBUG
|
||||
@@ -146,7 +147,6 @@ void DebugComponent::dump_config() {
|
||||
device_info += "|EFuse MAC: ";
|
||||
device_info += mac;
|
||||
|
||||
const char *reset_reason;
|
||||
switch (rtc_get_reset_reason(0)) {
|
||||
case POWERON_RESET:
|
||||
reset_reason = "Power On Reset";
|
||||
@@ -196,7 +196,7 @@ void DebugComponent::dump_config() {
|
||||
default:
|
||||
reset_reason = "Unknown Reset Reason";
|
||||
}
|
||||
ESP_LOGD(TAG, "Reset Reason: %s", reset_reason);
|
||||
ESP_LOGD(TAG, "Reset Reason: %s", reset_reason.c_str());
|
||||
device_info += "|Reset: ";
|
||||
device_info += reset_reason;
|
||||
|
||||
@@ -270,6 +270,8 @@ void DebugComponent::dump_config() {
|
||||
device_info += ESP.getResetReason().c_str();
|
||||
device_info += "|";
|
||||
device_info += ESP.getResetInfo().c_str();
|
||||
|
||||
reset_reason = ESP.getResetReason().c_str();
|
||||
#endif
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
@@ -278,6 +280,9 @@ void DebugComponent::dump_config() {
|
||||
device_info.resize(255);
|
||||
this->device_info_->publish_state(device_info);
|
||||
}
|
||||
if (this->reset_reason_ != nullptr) {
|
||||
this->reset_reason_->publish_state(reset_reason);
|
||||
}
|
||||
#endif // USE_TEXT_SENSOR
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user