From 8aac2f525ead462ff0541909f4ebfd4d5cb5ad31 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 5 Jul 2025 16:01:59 -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, 6 insertions(+), 7 deletions(-) diff --git a/esphome/components/deep_sleep/deep_sleep_component.cpp b/esphome/components/deep_sleep/deep_sleep_component.cpp index 880db6c56b..747085163d 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_BY_PREVENT; + this->sleep_state_ = SLEEP_STATE_BLOCKED; 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 by prevent flag, try to sleep now - if (this->sleep_state_ == SLEEP_STATE_BLOCKED_BY_PREVENT) { + // If sleep was blocked, try to sleep now + if (this->sleep_state_ == SLEEP_STATE_BLOCKED) { 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 c056820eed..d1935d63fa 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.h +++ b/esphome/components/deep_sleep/deep_sleep_component.h @@ -124,8 +124,7 @@ class DeepSleepComponent : public Component { #endif enum SleepState : uint8_t { SLEEP_STATE_IDLE, - SLEEP_STATE_BLOCKED_BY_PREVENT, - SLEEP_STATE_BLOCKED_BY_WAKEUP_PIN, + SLEEP_STATE_BLOCKED, 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 7927f5425c..f8f5b85b54 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_BY_WAKEUP_PIN) { - this->sleep_state_ = SLEEP_STATE_BLOCKED_BY_WAKEUP_PIN; + if (this->sleep_state_ != SLEEP_STATE_BLOCKED) { + this->sleep_state_ = SLEEP_STATE_BLOCKED; this->status_set_warning(); ESP_LOGW(TAG, "Waiting for wakeup pin state change"); // Set up monitoring - check pin state every 100ms