Added trivial dry contact protocol, no state, only door toggle
This commit is contained in:
parent
1274ef9172
commit
e0f1b2b61f
|
@ -33,7 +33,8 @@ CONF_PROTOCOL = "protocol"
|
||||||
|
|
||||||
PROTOCOL_SECPLUSV1 = "secplusv1"
|
PROTOCOL_SECPLUSV1 = "secplusv1"
|
||||||
PROTOCOL_SECPLUSV2 = "secplusv2"
|
PROTOCOL_SECPLUSV2 = "secplusv2"
|
||||||
SUPPORTED_PROTOCOLS = [PROTOCOL_SECPLUSV1, PROTOCOL_SECPLUSV2]
|
PROTOCOL_DRYCONTACT = "drycontact"
|
||||||
|
SUPPORTED_PROTOCOLS = [PROTOCOL_SECPLUSV1, PROTOCOL_SECPLUSV2, PROTOCOL_DRYCONTACT]
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.Schema(
|
CONFIG_SCHEMA = cv.Schema(
|
||||||
{
|
{
|
||||||
|
@ -99,4 +100,6 @@ async def to_code(config):
|
||||||
cg.add_define("PROTOCOL_SECPLUSV1")
|
cg.add_define("PROTOCOL_SECPLUSV1")
|
||||||
elif config[CONF_PROTOCOL] == PROTOCOL_SECPLUSV2:
|
elif config[CONF_PROTOCOL] == PROTOCOL_SECPLUSV2:
|
||||||
cg.add_define("PROTOCOL_SECPLUSV2")
|
cg.add_define("PROTOCOL_SECPLUSV2")
|
||||||
|
elif config[CONF_PROTOCOL] == PROTOCOL_DRYCONTACT:
|
||||||
|
cg.add_define("PROTOCOL_DRYCONTACT")
|
||||||
cg.add(var.init_protocol())
|
cg.add(var.init_protocol())
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -16,6 +16,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "secplus1.h"
|
#include "secplus1.h"
|
||||||
#include "secplus2.h"
|
#include "secplus2.h"
|
||||||
|
#include "dry_contact.h"
|
||||||
|
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
#include "esphome/core/gpio.h"
|
#include "esphome/core/gpio.h"
|
||||||
|
@ -64,6 +65,9 @@ namespace ratgdo {
|
||||||
#endif
|
#endif
|
||||||
#ifdef PROTOCOL_SECPLUSV1
|
#ifdef PROTOCOL_SECPLUSV1
|
||||||
this->protocol_ = new secplus1::Secplus1();
|
this->protocol_ = new secplus1::Secplus1();
|
||||||
|
#endif
|
||||||
|
#ifdef PROTOCOL_DRYCONTACT
|
||||||
|
this->protocol_ = new dry_contact::DryContact();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue