diff --git a/components/ratgdo/__init__.py b/components/ratgdo/__init__.py index e262bcf..f55ae1e 100644 --- a/components/ratgdo/__init__.py +++ b/components/ratgdo/__init__.py @@ -33,7 +33,8 @@ CONF_PROTOCOL = "protocol" PROTOCOL_SECPLUSV1 = "secplusv1" PROTOCOL_SECPLUSV2 = "secplusv2" -SUPPORTED_PROTOCOLS = [PROTOCOL_SECPLUSV1, PROTOCOL_SECPLUSV2] +PROTOCOL_DRYCONTACT = "drycontact" +SUPPORTED_PROTOCOLS = [PROTOCOL_SECPLUSV1, PROTOCOL_SECPLUSV2, PROTOCOL_DRYCONTACT] CONFIG_SCHEMA = cv.Schema( { @@ -99,4 +100,6 @@ async def to_code(config): cg.add_define("PROTOCOL_SECPLUSV1") elif config[CONF_PROTOCOL] == PROTOCOL_SECPLUSV2: cg.add_define("PROTOCOL_SECPLUSV2") + elif config[CONF_PROTOCOL] == PROTOCOL_DRYCONTACT: + cg.add_define("PROTOCOL_DRYCONTACT") cg.add(var.init_protocol()) diff --git a/components/ratgdo/dry_contact.cpp b/components/ratgdo/dry_contact.cpp new file mode 100644 index 0000000..607badf --- /dev/null +++ b/components/ratgdo/dry_contact.cpp @@ -0,0 +1,75 @@ + +#include "ratgdo.h" +#include "dry_contact.h" + +#include "esphome/core/log.h" +#include "esphome/core/scheduler.h" +#include "esphome/core/gpio.h" + + + +namespace esphome { +namespace ratgdo { +namespace dry_contact { + + static const char* const TAG = "ratgdo_dry_contact"; + + + void DryContact::setup(RATGDOComponent* ratgdo, Scheduler* scheduler, InternalGPIOPin* rx_pin, InternalGPIOPin* tx_pin) + { + this->ratgdo_ = ratgdo; + this->scheduler_ = scheduler; + this->tx_pin_ = tx_pin; + this->rx_pin_ = rx_pin; + } + + + void DryContact::loop() + { + } + + void DryContact::dump_config() + { + ESP_LOGCONFIG(TAG, " Protocol: dry contact"); + } + + + void DryContact::sync() + { + } + + + void DryContact::light_action(LightAction action) + { + ESP_LOG1(TAG, "Ignoring light action: %s", LightAction_to_string(action)); + return; + } + + void DryContact::lock_action(LockAction action) + { + ESP_LOG1(TAG, "Ignoring lock action: %s", LockAction_to_string(action)); + return; + } + + void DryContact::door_action(DoorAction action) + { + if (action != DoorAction::TOGGLE) { + ESP_LOG1(TAG, "Ignoring door action: %s", DoorAction_to_string(action)); + return; + } + ESP_LOG1(TAG, "Door action: %s", DoorAction_to_string(action)); + + this->tx_pin_->digital_write(1); + this->scheduler_->set_timeout(this->ratgdo_, "", 200, [=] { + this->tx_pin_->digital_write(0); + }); + } + + Result DryContact::call(Args args) + { + return {}; + } + +} // namespace DryContact +} // namespace ratgdo +} // namespace esphome diff --git a/components/ratgdo/dry_contact.h b/components/ratgdo/dry_contact.h new file mode 100644 index 0000000..d4c3446 --- /dev/null +++ b/components/ratgdo/dry_contact.h @@ -0,0 +1,45 @@ +#pragma once + +#include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial +#include "esphome/core/optional.h" + +#include "ratgdo_state.h" +#include "protocol.h" +#include "callbacks.h" +#include "observable.h" + +namespace esphome { + + class Scheduler; + class InternalGPIOPin; + +namespace ratgdo { +namespace dry_contact { + + using namespace esphome::ratgdo::protocol; + + class DryContact : public Protocol { + public: + void setup(RATGDOComponent* ratgdo, Scheduler* scheduler, InternalGPIOPin* rx_pin, InternalGPIOPin* tx_pin); + void loop(); + void dump_config(); + + void sync(); + + void light_action(LightAction action); + void lock_action(LockAction action); + void door_action(DoorAction action); + + Result call(Args args); + + protected: + InternalGPIOPin* tx_pin_; + InternalGPIOPin* rx_pin_; + + RATGDOComponent* ratgdo_; + Scheduler* scheduler_; + }; + +} // namespace secplus1 +} // namespace ratgdo +} // namespace esphome diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index b41e7bd..6f84a70 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -16,6 +16,7 @@ #include "common.h" #include "secplus1.h" #include "secplus2.h" +#include "dry_contact.h" #include "esphome/core/log.h" #include "esphome/core/gpio.h" @@ -64,6 +65,9 @@ namespace ratgdo { #endif #ifdef PROTOCOL_SECPLUSV1 this->protocol_ = new secplus1::Secplus1(); +#endif +#ifdef PROTOCOL_DRYCONTACT + this->protocol_ = new dry_contact::DryContact(); #endif }