From 1f6239ee1ddb821a079583591b7ec0c3de10de41 Mon Sep 17 00:00:00 2001 From: Paul Wieland Date: Sat, 23 Mar 2024 12:24:11 -0400 Subject: [PATCH] setup door controls --- base_drycontact.yaml | 2 +- components/ratgdo/dry_contact.cpp | 24 ++++++++++++++---------- components/ratgdo/dry_contact.h | 1 + 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/base_drycontact.yaml b/base_drycontact.yaml index 19f051b..3f651cb 100644 --- a/base_drycontact.yaml +++ b/base_drycontact.yaml @@ -202,7 +202,7 @@ button: - platform: template id: ${id_prefix}_toggle_door - name: "Toggle door!" + name: "Toggle door" on_press: then: lambda: !lambda |- diff --git a/components/ratgdo/dry_contact.cpp b/components/ratgdo/dry_contact.cpp index e1fc4a9..76dbc91 100644 --- a/components/ratgdo/dry_contact.cpp +++ b/components/ratgdo/dry_contact.cpp @@ -23,6 +23,7 @@ namespace ratgdo { this->last_open_limit_ = 0; this->close_limit_reached_ = 0; this->last_close_limit_ = 0; + this->door_state_ = DoorState::UNKNOWN; } void DryContact::loop() @@ -58,23 +59,21 @@ namespace ratgdo { } void DryContact::send_door_state(){ - DoorState door_state; - if(this->open_limit_reached_){ - door_state = DoorState::OPEN; + this->door_state_ = DoorState::OPEN; }else if(this->close_limit_reached_){ - door_state = DoorState::CLOSED; + this->door_state_ = DoorState::CLOSED; }else if(!this->close_limit_reached_ && !this->open_limit_reached_){ if(this->last_close_limit_){ - door_state = DoorState::OPENING; + this->door_state_ = DoorState::OPENING; } if(this->last_open_limit_){ - door_state = DoorState::CLOSING; + this->door_state_ = DoorState::CLOSING; } } - this->ratgdo_->received(door_state); + this->ratgdo_->received(this->door_state_); } void DryContact::light_action(LightAction action) @@ -91,14 +90,19 @@ namespace ratgdo { void DryContact::door_action(DoorAction action) { - if (action != DoorAction::TOGGLE) { - ESP_LOG1(TAG, "Ignoring door action: %s", DoorAction_to_string(action)); + if (action == DoorAction::OPEN && this->door_state_ != DoorState::CLOSED) { + ESP_LOGW(TAG, "The door is not closed. Ignoring door action: %s", DoorAction_to_string(action)); return; } + if (action == DoorAction::CLOSE && this->door_state_ != DoorState::OPEN) { + ESP_LOGW(TAG, "The door is not open. Ignoring door action: %s", DoorAction_to_string(action)); + return; + } + ESP_LOG1(TAG, "Door action: %s", DoorAction_to_string(action)); this->tx_pin_->digital_write(1); - this->scheduler_->set_timeout(this->ratgdo_, "", 200, [=] { + this->scheduler_->set_timeout(this->ratgdo_, "", 500, [=] { this->tx_pin_->digital_write(0); }); } diff --git a/components/ratgdo/dry_contact.h b/components/ratgdo/dry_contact.h index 1a1f15d..ee5a69e 100644 --- a/components/ratgdo/dry_contact.h +++ b/components/ratgdo/dry_contact.h @@ -46,6 +46,7 @@ namespace ratgdo { RATGDOComponent* ratgdo_; Scheduler* scheduler_; + DoorState door_state_; bool open_limit_reached_; bool last_open_limit_; bool close_limit_reached_;