This commit is contained in:
Kevin P. Fleming 2024-06-27 14:58:46 +00:00 committed by GitHub
commit a25a520514
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 12 deletions

View File

@ -1,11 +1,12 @@
#include "dry_contact.h"
#include "ratgdo.h" #include "ratgdo.h"
#ifdef PROTOCOL_DRYCONTACT
#include "dry_contact.h"
#include "esphome/core/gpio.h" #include "esphome/core/gpio.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/scheduler.h" #include "esphome/core/scheduler.h"
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
namespace esphome { namespace esphome {
namespace ratgdo { namespace ratgdo {
@ -127,6 +128,8 @@ namespace ratgdo {
return {}; return {};
} }
} // namespace DryContact } // namespace dry_contact
} // namespace ratgdo } // namespace ratgdo
} // namespace esphome } // namespace esphome
#endif

View File

@ -1,9 +1,12 @@
#pragma once #pragma once
#include "esphome/core/defines.h"
#ifdef PROTOCOL_DRYCONTACT
#include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial #include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial
#include "esphome/core/optional.h" #include "esphome/core/optional.h"
#include "esphome/core/gpio.h" #include "esphome/core/gpio.h"
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
#include "callbacks.h" #include "callbacks.h"
#include "observable.h" #include "observable.h"
@ -71,6 +74,8 @@ namespace ratgdo {
}; };
} // namespace secplus1 } // namespace dry_contact
} // namespace ratgdo } // namespace ratgdo
} // namespace esphome } // namespace esphome
#endif

View File

@ -686,8 +686,9 @@ namespace ratgdo {
this->learn_state.subscribe([=](LearnState state) { defer("learn_state", [=] { f(state); }); }); this->learn_state.subscribe([=](LearnState state) { defer("learn_state", [=] { f(state); }); });
} }
#ifdef PROTOCOL_DRYCONTACT
// dry contact methods // dry contact methods
void RATGDOComponent::set_dry_contact_open_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor) void RATGDOComponent::set_dry_contact_open_sensor(esphome::binary_sensor::BinarySensor* dry_contact_open_sensor)
{ {
dry_contact_open_sensor_ = dry_contact_open_sensor; dry_contact_open_sensor_ = dry_contact_open_sensor;
dry_contact_open_sensor_->add_on_state_callback([this](bool sensor_value) dry_contact_open_sensor_->add_on_state_callback([this](bool sensor_value)
@ -697,7 +698,7 @@ namespace ratgdo {
); );
} }
void RATGDOComponent::set_dry_contact_close_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor) void RATGDOComponent::set_dry_contact_close_sensor(esphome::binary_sensor::BinarySensor* dry_contact_close_sensor)
{ {
dry_contact_close_sensor_ = dry_contact_close_sensor; dry_contact_close_sensor_ = dry_contact_close_sensor;
dry_contact_close_sensor_->add_on_state_callback([this](bool sensor_value) dry_contact_close_sensor_->add_on_state_callback([this](bool sensor_value)
@ -706,6 +707,7 @@ namespace ratgdo {
} }
); );
} }
#endif
} // namespace ratgdo } // namespace ratgdo
} // namespace esphome } // namespace esphome

View File

@ -13,10 +13,13 @@
#pragma once #pragma once
#include "esphome/core/defines.h"
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/hal.h" #include "esphome/core/hal.h"
#include "esphome/core/preferences.h" #include "esphome/core/preferences.h"
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h" #ifdef PROTOCOL_DRYCONTACT
#include "esphome/components/binary_sensor/binary_sensor.h"
#endif
#include "callbacks.h" #include "callbacks.h"
#include "macros.h" #include "macros.h"
@ -92,11 +95,13 @@ namespace ratgdo {
void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; } void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; }
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; } void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; }
#ifdef PROTOCOL_DRYCONTACT
// dry contact methods // dry contact methods
void set_dry_contact_open_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_); void set_dry_contact_open_sensor(esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_);
void set_dry_contact_close_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor_); void set_dry_contact_close_sensor(esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_);
void set_discrete_open_pin(InternalGPIOPin* pin){ this->protocol_->set_discrete_open_pin(pin); } void set_discrete_open_pin(InternalGPIOPin* pin){ this->protocol_->set_discrete_open_pin(pin); }
void set_discrete_close_pin(InternalGPIOPin* pin){ this->protocol_->set_discrete_close_pin(pin); } void set_discrete_close_pin(InternalGPIOPin* pin){ this->protocol_->set_discrete_close_pin(pin); }
#endif
Result call_protocol(Args args); Result call_protocol(Args args);
@ -181,8 +186,10 @@ namespace ratgdo {
InternalGPIOPin* output_gdo_pin_; InternalGPIOPin* output_gdo_pin_;
InternalGPIOPin* input_gdo_pin_; InternalGPIOPin* input_gdo_pin_;
InternalGPIOPin* input_obst_pin_; InternalGPIOPin* input_obst_pin_;
esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_; #ifdef PROTOCOL_DRYCONTACT
esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor_; esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_;
esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_;
#endif
}; // RATGDOComponent }; // RATGDOComponent
} // namespace ratgdo } // namespace ratgdo