Skip to content

Commit 9df4ceb

Browse files
authored
Improve compatibility for non-dry-contact configurations. (#265)
1 parent b148105 commit 9df4ceb

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

components/ratgdo/dry_contact.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

2-
#include "dry_contact.h"
32
#include "ratgdo.h"
43

5-
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
4+
#ifdef PROTOCOL_DRYCONTACT
5+
6+
#include "dry_contact.h"
67
#include "esphome/core/gpio.h"
78
#include "esphome/core/log.h"
89
#include "esphome/core/scheduler.h"
@@ -128,6 +129,8 @@ namespace ratgdo {
128129
return {};
129130
}
130131

131-
} // namespace DryContact
132+
} // namespace dry_contact
132133
} // namespace ratgdo
133134
} // namespace esphome
135+
136+
#endif

components/ratgdo/dry_contact.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#pragma once
22

3+
#include "esphome/core/defines.h"
4+
5+
#ifdef PROTOCOL_DRYCONTACT
6+
37
#include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial
4-
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
58
#include "esphome/core/gpio.h"
69
#include "esphome/core/optional.h"
710

@@ -72,6 +75,8 @@ namespace ratgdo {
7275
bool last_close_limit_;
7376
};
7477

75-
} // namespace secplus1
78+
} // namespace dry_contact
7679
} // namespace ratgdo
7780
} // namespace esphome
81+
82+
#endif

components/ratgdo/ratgdo.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -680,22 +680,24 @@ namespace ratgdo {
680680
this->learn_state.subscribe([=](LearnState state) { defer("learn_state", [=] { f(state); }); });
681681
}
682682

683+
#ifdef PROTOCOL_DRYCONTACT
683684
// dry contact methods
684-
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)
685686
{
686687
dry_contact_open_sensor_ = dry_contact_open_sensor;
687688
dry_contact_open_sensor_->add_on_state_callback([this](bool sensor_value) {
688689
this->protocol_->set_open_limit(sensor_value);
689690
});
690691
}
691692

692-
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)
693694
{
694695
dry_contact_close_sensor_ = dry_contact_close_sensor;
695696
dry_contact_close_sensor_->add_on_state_callback([this](bool sensor_value) {
696697
this->protocol_->set_close_limit(sensor_value);
697698
});
698699
}
700+
#endif
699701

700702
} // namespace ratgdo
701703
} // namespace esphome

components/ratgdo/ratgdo.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
#pragma once
1515

16-
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
1716
#include "esphome/core/component.h"
17+
#include "esphome/core/defines.h"
1818
#include "esphome/core/hal.h"
1919
#include "esphome/core/preferences.h"
20+
#ifdef PROTOCOL_DRYCONTACT
21+
#include "esphome/components/binary_sensor/binary_sensor.h"
22+
#endif
2023

2124
#include "callbacks.h"
2225
#include "macros.h"
@@ -92,11 +95,13 @@ namespace ratgdo {
9295
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; }
9396
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; }
9497

98+
#ifdef PROTOCOL_DRYCONTACT
9599
// dry contact methods
96-
void set_dry_contact_open_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_);
97-
void set_dry_contact_close_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor_);
100+
void set_dry_contact_open_sensor(esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_);
101+
void set_dry_contact_close_sensor(esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_);
98102
void set_discrete_open_pin(InternalGPIOPin* pin) { this->protocol_->set_discrete_open_pin(pin); }
99103
void set_discrete_close_pin(InternalGPIOPin* pin) { this->protocol_->set_discrete_close_pin(pin); }
104+
#endif
100105

101106
Result call_protocol(Args args);
102107

@@ -181,8 +186,10 @@ namespace ratgdo {
181186
InternalGPIOPin* output_gdo_pin_;
182187
InternalGPIOPin* input_gdo_pin_;
183188
InternalGPIOPin* input_obst_pin_;
184-
esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_;
185-
esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor_;
189+
#ifdef PROTOCOL_DRYCONTACT
190+
esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_;
191+
esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_;
192+
#endif
186193
}; // RATGDOComponent
187194

188195
} // namespace ratgdo

0 commit comments

Comments
 (0)