mirror of
https://github.com/esphome/esphome.git
synced 2025-08-06 18:37:47 +00:00
simplify
This commit is contained in:
parent
f85dcdca4e
commit
8aac2f525e
@ -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
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user