organize dry contact methods & fix initial limit switch state

This commit is contained in:
Paul Wieland 2024-04-17 14:56:48 -04:00
parent 31fa0e8082
commit f72cea2e8b
5 changed files with 26 additions and 15 deletions

View File

@ -102,9 +102,10 @@ namespace ratgdo {
virtual void dump_config(); virtual void dump_config();
virtual void sync(); virtual void sync();
// dry contact methods
virtual void set_open_limit(bool); virtual void set_open_limit(bool);
virtual void set_close_limit(bool); virtual void set_close_limit(bool);
virtual void set_discrete_open_pin(InternalGPIOPin* pin); virtual void set_discrete_open_pin(InternalGPIOPin* pin);
virtual void set_discrete_close_pin(InternalGPIOPin* pin); virtual void set_discrete_close_pin(InternalGPIOPin* pin);

View File

@ -418,16 +418,13 @@ namespace ratgdo {
void RATGDOComponent::sync() void RATGDOComponent::sync()
{ {
this->protocol_->sync(); this->protocol_->sync();
}
void RATGDOComponent::set_open_limit(bool state) // dry contact protocol:
{ // needed to trigger the intial state of the limit switch sensors
this->protocol_->set_open_limit(state); // ideally this would be in drycontact::sync
} // this->dry_contact_open_sensor_->state;
this->protocol_->set_open_limit(this->dry_contact_open_sensor_->state);
void RATGDOComponent::set_close_limit(bool state) this->protocol_->set_close_limit(this->dry_contact_close_sensor_->state);
{
this->protocol_->set_close_limit(state);
} }
void RATGDOComponent::door_open() void RATGDOComponent::door_open()
@ -683,21 +680,23 @@ namespace ratgdo {
this->learn_state.subscribe([=](LearnState state) { defer("learn_state", [=] { f(state); }); }); this->learn_state.subscribe([=](LearnState state) { defer("learn_state", [=] { f(state); }); });
} }
// 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::gpio::GPIOBinarySensor* 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)
{ {
this->set_open_limit(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::gpio::GPIOBinarySensor* 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)
{ {
this->set_close_limit(sensor_value); this->protocol_->set_close_limit(sensor_value);
} }
); );
} }

View File

@ -92,9 +92,9 @@ 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; }
// dry contact methods
void set_dry_contact_open_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_); 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_close_sensor(esphome::gpio::GPIOBinarySensor* 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); }
@ -152,8 +152,6 @@ namespace ratgdo {
void query_status(); void query_status();
void query_openings(); void query_openings();
void sync(); void sync();
void set_open_limit(bool);
void set_close_limit(bool);
// children subscriptions // children subscriptions
void subscribe_rolling_code_counter(std::function<void(uint32_t)>&& f); void subscribe_rolling_code_counter(std::function<void(uint32_t)>&& f);

View File

@ -96,6 +96,13 @@ namespace ratgdo {
const Traits& traits() const { return this->traits_; } const Traits& traits() const { return this->traits_; }
// methods not used by secplus1
void set_open_limit(bool state){}
void set_close_limit(bool state){}
void set_discrete_open_pin(InternalGPIOPin* pin){}
void set_discrete_close_pin(InternalGPIOPin* pin){}
protected: protected:
void wall_panel_emulation(size_t index = 0); void wall_panel_emulation(size_t index = 0);

View File

@ -101,6 +101,12 @@ namespace ratgdo {
const Traits& traits() const { return this->traits_; } const Traits& traits() const { return this->traits_; }
// methods not used by secplus2
void set_open_limit(bool state){}
void set_close_limit(bool state){}
void set_discrete_open_pin(InternalGPIOPin* pin){}
void set_discrete_close_pin(InternalGPIOPin* pin){}
protected: protected:
void increment_rolling_code_counter(int delta = 1); void increment_rolling_code_counter(int delta = 1);
void set_rolling_code_counter(uint32_t counter); void set_rolling_code_counter(uint32_t counter);