Compare commits
5 Commits
1dae32ae37
...
e2a43b84eb
Author | SHA1 | Date |
---|---|---|
Matt MacAdam | e2a43b84eb | |
J. Nick Koston | 9fc5cc4510 | |
Brendan Davis | 38d2508edc | |
Kevin P. Fleming | 9df4cebd53 | |
Paul Wieland | b148105423 |
|
@ -18,9 +18,13 @@ CoverOpeningTrigger = ratgdo_ns.class_(
|
|||
CoverClosingTrigger = ratgdo_ns.class_(
|
||||
"CoverClosingTrigger", automation.Trigger.template()
|
||||
)
|
||||
CoverStateTrigger = ratgdo_ns.class_(
|
||||
"CoverStateTrigger", automation.Trigger.template()
|
||||
)
|
||||
|
||||
CONF_ON_OPENING = "on_opening"
|
||||
CONF_ON_CLOSING = "on_closing"
|
||||
CONF_ON_STATE_CHANGE = "on_state_change"
|
||||
|
||||
CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(
|
||||
{
|
||||
|
@ -31,6 +35,9 @@ CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(
|
|||
cv.Optional(CONF_ON_CLOSING): automation.validate_automation(
|
||||
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CoverClosingTrigger)}
|
||||
),
|
||||
cv.Optional(CONF_ON_STATE_CHANGE): automation.validate_automation(
|
||||
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CoverStateTrigger)}
|
||||
),
|
||||
}
|
||||
).extend(RATGDO_CLIENT_SCHMEA)
|
||||
|
||||
|
@ -46,5 +53,8 @@ async def to_code(config):
|
|||
for conf in config.get(CONF_ON_CLOSING, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
for conf in config.get(CONF_ON_STATE_CHANGE, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
|
||||
await register_ratgdo_child(var, config)
|
||||
|
|
|
@ -31,5 +31,15 @@ namespace ratgdo {
|
|||
}
|
||||
};
|
||||
|
||||
class CoverStateTrigger : public Trigger<> {
|
||||
public:
|
||||
CoverStateTrigger(cover::Cover* a_cover)
|
||||
{
|
||||
a_cover->add_on_state_callback([this, a_cover]() {
|
||||
this->trigger();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
|
||||
#include "dry_contact.h"
|
||||
#include "ratgdo.h"
|
||||
|
||||
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
|
||||
#include "esphome/core/gpio.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/scheduler.h"
|
||||
#include "ratgdo.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ratgdo {
|
||||
|
@ -128,6 +126,6 @@ namespace ratgdo {
|
|||
return {};
|
||||
}
|
||||
|
||||
} // namespace DryContact
|
||||
} // namespace dry_contact
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
#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"
|
||||
|
||||
|
@ -72,6 +73,6 @@ namespace ratgdo {
|
|||
bool last_close_limit_;
|
||||
};
|
||||
|
||||
} // namespace secplus1
|
||||
} // namespace dry_contact
|
||||
} // namespace ratgdo
|
||||
} // namespace esphome
|
||||
|
|
|
@ -38,15 +38,9 @@ namespace ratgdo {
|
|||
this->input_gdo_pin_->setup();
|
||||
this->input_gdo_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
|
||||
if (this->input_obst_pin_ == nullptr) {
|
||||
// Our base.yaml is always going to set this so we check for 0
|
||||
// as well to avoid a breaking change.
|
||||
this->obstruction_from_status_ = true;
|
||||
} else {
|
||||
this->input_obst_pin_->setup();
|
||||
this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT);
|
||||
this->input_obst_pin_->attach_interrupt(RATGDOStore::isr_obstruction, &this->isr_store_, gpio::INTERRUPT_FALLING_EDGE);
|
||||
}
|
||||
this->input_obst_pin_->setup();
|
||||
this->input_obst_pin_->pin_mode(gpio::FLAG_INPUT);
|
||||
this->input_obst_pin_->attach_interrupt(RATGDOStore::isr_obstruction, &this->isr_store_, gpio::INTERRUPT_FALLING_EDGE);
|
||||
|
||||
this->protocol_->setup(this, &App.scheduler, this->input_gdo_pin_, this->output_gdo_pin_);
|
||||
|
||||
|
@ -76,9 +70,7 @@ namespace ratgdo {
|
|||
|
||||
void RATGDOComponent::loop()
|
||||
{
|
||||
if (!this->obstruction_from_status_) {
|
||||
this->obstruction_loop();
|
||||
}
|
||||
this->obstruction_loop();
|
||||
this->protocol_->loop();
|
||||
}
|
||||
|
||||
|
@ -87,11 +79,7 @@ namespace ratgdo {
|
|||
ESP_LOGCONFIG(TAG, "Setting up RATGDO...");
|
||||
LOG_PIN(" Output GDO Pin: ", this->output_gdo_pin_);
|
||||
LOG_PIN(" Input GDO Pin: ", this->input_gdo_pin_);
|
||||
if (this->obstruction_from_status_) {
|
||||
ESP_LOGCONFIG(TAG, " Input Obstruction Pin: not used, will detect from GDO status");
|
||||
} else {
|
||||
LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_);
|
||||
}
|
||||
LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_);
|
||||
this->protocol_->dump_config();
|
||||
}
|
||||
|
||||
|
@ -218,7 +206,7 @@ namespace ratgdo {
|
|||
|
||||
void RATGDOComponent::received(const ObstructionState obstruction_state)
|
||||
{
|
||||
if (this->obstruction_from_status_) {
|
||||
if (!this->obstruction_sensor_detected_) {
|
||||
ESP_LOGD(TAG, "Obstruction: state=%s", ObstructionState_to_string(*this->obstruction_state));
|
||||
|
||||
this->obstruction_state = obstruction_state;
|
||||
|
@ -378,6 +366,7 @@ namespace ratgdo {
|
|||
// check to see if we got more then PULSES_LOWER_LIMIT pulses
|
||||
if (this->isr_store_.obstruction_low_count > PULSES_LOWER_LIMIT) {
|
||||
this->obstruction_state = ObstructionState::CLEAR;
|
||||
this->obstruction_sensor_detected_ = true;
|
||||
} else if (this->isr_store_.obstruction_low_count == 0) {
|
||||
// if there have been no pulses the line is steady high or low
|
||||
if (!this->input_obst_pin_->digital_read()) {
|
||||
|
@ -471,7 +460,12 @@ namespace ratgdo {
|
|||
return;
|
||||
}
|
||||
|
||||
this->door_action(DoorAction::CLOSE);
|
||||
if (this->obstruction_sensor_detected_) {
|
||||
this->door_action(DoorAction::CLOSE);
|
||||
} else if (*this->door_state == DoorState::OPEN) {
|
||||
ESP_LOGD(TAG, "No obstruction sensors detected. Close using TOGGLE.");
|
||||
this->door_action(DoorAction::TOGGLE);
|
||||
}
|
||||
|
||||
if (*this->closing_duration > 0) {
|
||||
// query state in case we don't get a status message
|
||||
|
@ -687,7 +681,7 @@ namespace ratgdo {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
|
@ -695,7 +689,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_->add_on_state_callback([this](bool sensor_value) {
|
||||
|
|
|
@ -13,8 +13,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/preferences.h"
|
||||
|
||||
|
@ -93,8 +94,8 @@ namespace ratgdo {
|
|||
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_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); }
|
||||
|
||||
|
@ -176,13 +177,13 @@ namespace ratgdo {
|
|||
protected:
|
||||
RATGDOStore isr_store_ {};
|
||||
protocol::Protocol* protocol_;
|
||||
bool obstruction_from_status_ { false };
|
||||
bool obstruction_sensor_detected_ { false };
|
||||
|
||||
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_;
|
||||
esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_;
|
||||
esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_;
|
||||
}; // RATGDOComponent
|
||||
|
||||
} // namespace ratgdo
|
||||
|
|
Loading…
Reference in New Issue