@@ -38,15 +38,9 @@ namespace ratgdo {
38
38
this ->input_gdo_pin_ ->setup ();
39
39
this ->input_gdo_pin_ ->pin_mode (gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
40
40
41
- if (this ->input_obst_pin_ == nullptr ) {
42
- // Our base.yaml is always going to set this so we check for 0
43
- // as well to avoid a breaking change.
44
- this ->obstruction_from_status_ = true ;
45
- } else {
46
- this ->input_obst_pin_ ->setup ();
47
- this ->input_obst_pin_ ->pin_mode (gpio::FLAG_INPUT);
48
- this ->input_obst_pin_ ->attach_interrupt (RATGDOStore::isr_obstruction, &this ->isr_store_ , gpio::INTERRUPT_FALLING_EDGE);
49
- }
41
+ this ->input_obst_pin_ ->setup ();
42
+ this ->input_obst_pin_ ->pin_mode (gpio::FLAG_INPUT);
43
+ this ->input_obst_pin_ ->attach_interrupt (RATGDOStore::isr_obstruction, &this ->isr_store_ , gpio::INTERRUPT_FALLING_EDGE);
50
44
51
45
this ->protocol_ ->setup (this , &App.scheduler , this ->input_gdo_pin_ , this ->output_gdo_pin_ );
52
46
@@ -76,9 +70,7 @@ namespace ratgdo {
76
70
77
71
void RATGDOComponent::loop ()
78
72
{
79
- if (!this ->obstruction_from_status_ ) {
80
- this ->obstruction_loop ();
81
- }
73
+ this ->obstruction_loop ();
82
74
this ->protocol_ ->loop ();
83
75
}
84
76
@@ -87,11 +79,7 @@ namespace ratgdo {
87
79
ESP_LOGCONFIG (TAG, " Setting up RATGDO..." );
88
80
LOG_PIN (" Output GDO Pin: " , this ->output_gdo_pin_ );
89
81
LOG_PIN (" Input GDO Pin: " , this ->input_gdo_pin_ );
90
- if (this ->obstruction_from_status_ ) {
91
- ESP_LOGCONFIG (TAG, " Input Obstruction Pin: not used, will detect from GDO status" );
92
- } else {
93
- LOG_PIN (" Input Obstruction Pin: " , this ->input_obst_pin_ );
94
- }
82
+ LOG_PIN (" Input Obstruction Pin: " , this ->input_obst_pin_ );
95
83
this ->protocol_ ->dump_config ();
96
84
}
97
85
@@ -218,7 +206,7 @@ namespace ratgdo {
218
206
219
207
void RATGDOComponent::received (const ObstructionState obstruction_state)
220
208
{
221
- if (this ->obstruction_from_status_ ) {
209
+ if (! this ->obstruction_sensor_detected_ ) {
222
210
ESP_LOGD (TAG, " Obstruction: state=%s" , ObstructionState_to_string (*this ->obstruction_state ));
223
211
224
212
this ->obstruction_state = obstruction_state;
@@ -378,6 +366,7 @@ namespace ratgdo {
378
366
// check to see if we got more then PULSES_LOWER_LIMIT pulses
379
367
if (this ->isr_store_ .obstruction_low_count > PULSES_LOWER_LIMIT) {
380
368
this ->obstruction_state = ObstructionState::CLEAR;
369
+ this ->obstruction_sensor_detected_ = true ;
381
370
} else if (this ->isr_store_ .obstruction_low_count == 0 ) {
382
371
// if there have been no pulses the line is steady high or low
383
372
if (!this ->input_obst_pin_ ->digital_read ()) {
@@ -471,7 +460,12 @@ namespace ratgdo {
471
460
return ;
472
461
}
473
462
474
- this ->door_action (DoorAction::CLOSE);
463
+ if (this ->obstruction_sensor_detected_ ) {
464
+ this ->door_action (DoorAction::CLOSE);
465
+ } else if (*this ->door_state == DoorState::OPEN) {
466
+ ESP_LOGD (TAG, " No obstruction sensors detected. Close using TOGGLE." );
467
+ this ->door_action (DoorAction::TOGGLE);
468
+ }
475
469
476
470
if (*this ->closing_duration > 0 ) {
477
471
// query state in case we don't get a status message
@@ -686,22 +680,24 @@ namespace ratgdo {
686
680
this ->learn_state .subscribe ([=](LearnState state) { defer (" learn_state" , [=] { f (state); }); });
687
681
}
688
682
683
+ #ifdef PROTOCOL_DRYCONTACT
689
684
// dry contact methods
690
- void RATGDOComponent::set_dry_contact_open_sensor (esphome::gpio::GPIOBinarySensor * dry_contact_open_sensor)
685
+ void RATGDOComponent::set_dry_contact_open_sensor (esphome::binary_sensor::BinarySensor * dry_contact_open_sensor)
691
686
{
692
687
dry_contact_open_sensor_ = dry_contact_open_sensor;
693
688
dry_contact_open_sensor_->add_on_state_callback ([this ](bool sensor_value) {
694
689
this ->protocol_ ->set_open_limit (sensor_value);
695
690
});
696
691
}
697
692
698
- void RATGDOComponent::set_dry_contact_close_sensor (esphome::gpio::GPIOBinarySensor * dry_contact_close_sensor)
693
+ void RATGDOComponent::set_dry_contact_close_sensor (esphome::binary_sensor::BinarySensor * dry_contact_close_sensor)
699
694
{
700
695
dry_contact_close_sensor_ = dry_contact_close_sensor;
701
696
dry_contact_close_sensor_->add_on_state_callback ([this ](bool sensor_value) {
702
697
this ->protocol_ ->set_close_limit (sensor_value);
703
698
});
704
699
}
700
+ #endif
705
701
706
702
} // namespace ratgdo
707
703
} // namespace esphome
0 commit comments