Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility for non-dry-contact configurations. #265

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions components/ratgdo/dry_contact.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

#include "dry_contact.h"
#include "ratgdo.h"

#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
#ifdef PROTOCOL_DRYCONTACT

#include "dry_contact.h"
#include "esphome/core/gpio.h"
#include "esphome/core/log.h"
#include "esphome/core/scheduler.h"
Expand Down Expand Up @@ -128,6 +129,8 @@ namespace ratgdo {
return {};
}

} // namespace DryContact
} // namespace dry_contact
} // namespace ratgdo
} // namespace esphome

#endif
9 changes: 7 additions & 2 deletions components/ratgdo/dry_contact.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#pragma once

#include "esphome/core/defines.h"

#ifdef PROTOCOL_DRYCONTACT

#include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
#include "esphome/core/gpio.h"
#include "esphome/core/optional.h"

Expand Down Expand Up @@ -72,6 +75,8 @@ namespace ratgdo {
bool last_close_limit_;
};

} // namespace secplus1
} // namespace dry_contact
} // namespace ratgdo
} // namespace esphome

#endif
6 changes: 4 additions & 2 deletions components/ratgdo/ratgdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,22 +686,24 @@ namespace ratgdo {
this->learn_state.subscribe([=](LearnState state) { defer("learn_state", [=] { f(state); }); });
}

#ifdef PROTOCOL_DRYCONTACT
// 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_->add_on_state_callback([this](bool sensor_value) {
this->protocol_->set_open_limit(sensor_value);
});
}

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_->add_on_state_callback([this](bool sensor_value) {
this->protocol_->set_close_limit(sensor_value);
});
}
#endif

} // namespace ratgdo
} // namespace esphome
17 changes: 12 additions & 5 deletions components/ratgdo/ratgdo.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

#pragma once

#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
#include "esphome/core/component.h"
#include "esphome/core/defines.h"
#include "esphome/core/hal.h"
#include "esphome/core/preferences.h"
#ifdef PROTOCOL_DRYCONTACT
#include "esphome/components/binary_sensor/binary_sensor.h"
#endif

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

#ifdef PROTOCOL_DRYCONTACT
// dry contact methods
void set_dry_contact_open_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_);
void set_dry_contact_close_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor_);
void set_dry_contact_open_sensor(esphome::binary_sensor::BinarySensor* dry_contact_open_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_close_pin(InternalGPIOPin* pin) { this->protocol_->set_discrete_close_pin(pin); }
#endif

Result call_protocol(Args args);

Expand Down Expand Up @@ -181,8 +186,10 @@ namespace ratgdo {
InternalGPIOPin* output_gdo_pin_;
InternalGPIOPin* input_gdo_pin_;
InternalGPIOPin* input_obst_pin_;
esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_;
esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor_;
#ifdef PROTOCOL_DRYCONTACT
esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_;
esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_;
#endif
}; // RATGDOComponent

} // namespace ratgdo
Expand Down
Loading