2
2
#include " dry_contact.h"
3
3
#include " ratgdo.h"
4
4
5
+ #include " esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
5
6
#include " esphome/core/gpio.h"
6
7
#include " esphome/core/log.h"
7
8
#include " esphome/core/scheduler.h"
8
- #include " esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
9
9
10
10
namespace esphome {
11
11
namespace ratgdo {
@@ -19,7 +19,7 @@ namespace ratgdo {
19
19
this ->scheduler_ = scheduler;
20
20
this ->tx_pin_ = tx_pin;
21
21
this ->rx_pin_ = rx_pin;
22
-
22
+
23
23
this ->open_limit_reached_ = 0 ;
24
24
this ->last_open_limit_ = 0 ;
25
25
this ->close_limit_reached_ = 0 ;
@@ -58,18 +58,19 @@ namespace ratgdo {
58
58
this ->close_limit_reached_ = state;
59
59
this ->send_door_state ();
60
60
}
61
-
62
- void DryContact::send_door_state (){
63
- if (this ->open_limit_reached_ ){
61
+
62
+ void DryContact::send_door_state ()
63
+ {
64
+ if (this ->open_limit_reached_ ) {
64
65
this ->door_state_ = DoorState::OPEN;
65
- }else if (this ->close_limit_reached_ ){
66
+ } else if (this ->close_limit_reached_ ) {
66
67
this ->door_state_ = DoorState::CLOSED;
67
- }else if (!this ->close_limit_reached_ && !this ->open_limit_reached_ ){
68
- if (this ->last_close_limit_ ){
68
+ } else if (!this ->close_limit_reached_ && !this ->open_limit_reached_ ) {
69
+ if (this ->last_close_limit_ ) {
69
70
this ->door_state_ = DoorState::OPENING;
70
71
}
71
72
72
- if (this ->last_open_limit_ ){
73
+ if (this ->last_open_limit_ ) {
73
74
this ->door_state_ = DoorState::CLOSING;
74
75
}
75
76
}
@@ -102,14 +103,14 @@ namespace ratgdo {
102
103
103
104
ESP_LOG1 (TAG, " Door action: %s" , DoorAction_to_string (action));
104
105
105
- if (action == DoorAction::OPEN){
106
+ if (action == DoorAction::OPEN) {
106
107
this ->discrete_open_pin_ ->digital_write (1 );
107
108
this ->scheduler_ ->set_timeout (this ->ratgdo_ , " " , 500 , [=] {
108
109
this ->discrete_open_pin_ ->digital_write (0 );
109
110
});
110
111
}
111
112
112
- if (action == DoorAction::CLOSE){
113
+ if (action == DoorAction::CLOSE) {
113
114
this ->discrete_close_pin_ ->digital_write (1 );
114
115
this ->scheduler_ ->set_timeout (this ->ratgdo_ , " " , 500 , [=] {
115
116
this ->discrete_close_pin_ ->digital_write (0 );
0 commit comments