From c34fc3c4c79833259d575aec30b0d435e0b673b2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 5 Jul 2025 16:07:43 -0500 Subject: [PATCH] simplify --- esphome/components/deep_sleep/deep_sleep_component.cpp | 6 +++--- esphome/components/deep_sleep/deep_sleep_component.h | 3 ++- esphome/components/deep_sleep/deep_sleep_esp32.cpp | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/esphome/components/deep_sleep/deep_sleep_component.cpp b/esphome/components/deep_sleep/deep_sleep_component.cpp index 747085163d..880db6c56b 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.cpp +++ b/esphome/components/deep_sleep/deep_sleep_component.cpp @@ -48,7 +48,7 @@ void DeepSleepComponent::begin_sleep(bool manual) { if (this->prevent_ && !manual) { // Sleep was prevented - this->sleep_state_ = SLEEP_STATE_BLOCKED; + this->sleep_state_ = SLEEP_STATE_BLOCKED_BY_PREVENT; ESP_LOGD(TAG, "Deep sleep blocked by prevent flag"); return; } @@ -79,8 +79,8 @@ void DeepSleepComponent::prevent_deep_sleep() { this->prevent_ = true; } void DeepSleepComponent::allow_deep_sleep() { this->prevent_ = false; - // If sleep was blocked, try to sleep now - if (this->sleep_state_ == SLEEP_STATE_BLOCKED) { + // If sleep was blocked by prevent flag, try to sleep now + if (this->sleep_state_ == SLEEP_STATE_BLOCKED_BY_PREVENT) { ESP_LOGD(TAG, "Deep sleep allowed, executing deferred sleep"); this->sleep_state_ = SLEEP_STATE_IDLE; // Schedule sleep for next loop iteration to avoid potential issues diff --git a/esphome/components/deep_sleep/deep_sleep_component.h b/esphome/components/deep_sleep/deep_sleep_component.h index d1935d63fa..c056820eed 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.h +++ b/esphome/components/deep_sleep/deep_sleep_component.h @@ -124,7 +124,8 @@ class DeepSleepComponent : public Component { #endif enum SleepState : uint8_t { SLEEP_STATE_IDLE, - SLEEP_STATE_BLOCKED, + SLEEP_STATE_BLOCKED_BY_PREVENT, + SLEEP_STATE_BLOCKED_BY_WAKEUP_PIN, SLEEP_STATE_ENTERING_SLEEP, }; diff --git a/esphome/components/deep_sleep/deep_sleep_esp32.cpp b/esphome/components/deep_sleep/deep_sleep_esp32.cpp index f8f5b85b54..7927f5425c 100644 --- a/esphome/components/deep_sleep/deep_sleep_esp32.cpp +++ b/esphome/components/deep_sleep/deep_sleep_esp32.cpp @@ -59,8 +59,8 @@ bool DeepSleepComponent::prepare_to_sleep_() { if (this->wakeup_pin_mode_ == WAKEUP_PIN_MODE_KEEP_AWAKE && this->wakeup_pin_ != nullptr && this->wakeup_pin_->digital_read()) { // Defer deep sleep until inactive - if (this->sleep_state_ != SLEEP_STATE_BLOCKED) { - this->sleep_state_ = SLEEP_STATE_BLOCKED; + if (this->sleep_state_ != SLEEP_STATE_BLOCKED_BY_WAKEUP_PIN) { + this->sleep_state_ = SLEEP_STATE_BLOCKED_BY_WAKEUP_PIN; this->status_set_warning(); ESP_LOGW(TAG, "Waiting for wakeup pin state change"); // Set up monitoring - check pin state every 100ms