diff --git a/components/ratgdo/__init__.py b/components/ratgdo/__init__.py index 0385be6..550aaec 100644 --- a/components/ratgdo/__init__.py +++ b/components/ratgdo/__init__.py @@ -9,8 +9,6 @@ DEPENDENCIES = ["preferences"] ratgdo_ns = cg.esphome_ns.namespace("ratgdo") RATGDO = ratgdo_ns.class_("RATGDOComponent", cg.Component) -CONF_ROLLING_CODES = "rolling_codes" - CONF_OUTPUT_GDO = "output_gdo_pin" DEFAULT_OUTPUT_GDO = 2 # D4 ed control terminal / GarageDoorOpener (UART1 TX) pin is D4 on D1 Mini @@ -38,7 +36,6 @@ DEFAULT_INPUT_RPM2 = 4 # D2 RPM2 rotary encoder input OR not used if using reed CONFIG_SCHEMA = cv.Schema( { cv.GenerateID(): cv.declare_id(RATGDO), - cv.Optional(CONF_ROLLING_CODES, default=True): cv.boolean, cv.Optional(CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO): pins.internal_gpio_input_pin_schema, cv.Optional(CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO): pins.internal_gpio_input_pin_schema, cv.Optional(CONF_TRIGGER_OPEN, default=DEFAULT_TRIGGER_OPEN): pins.internal_gpio_input_pin_schema, @@ -56,8 +53,6 @@ CONFIG_SCHEMA = cv.Schema( async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) - cg.add(var.set_rolling_codes(config[CONF_ROLLING_CODES])) - pin = await cg.gpio_pin_expression(config[CONF_OUTPUT_GDO]) cg.add(var.set_output_gdo_pin(pin)) pin = await cg.gpio_pin_expression(config[CONF_INPUT_GDO]) @@ -71,7 +66,7 @@ async def to_code(config): cg.add(var.set_trigger_close_pin(pin)) pin = await cg.gpio_pin_expression(config[CONF_TRIGGER_LIGHT]) cg.add(var.set_trigger_light_pin(pin)) - + pin = await cg.gpio_pin_expression(config[CONF_STATUS_DOOR]) cg.add(var.set_status_door_pin(pin)) pin = await cg.gpio_pin_expression(config[CONF_STATUS_OBST]) diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index bf3d6c3..cb102a7 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -19,23 +19,6 @@ namespace esphome { namespace ratgdo { static const char* const TAG = "ratgdo"; - /*** Static Codes ***/ - static const unsigned char SYNC1[] = { 0x55, 0x01, 0x00, 0x61, 0x12, 0x49, 0x2c, 0x92, 0x5b, 0x24, - 0x96, 0x86, 0x0b, 0x65, 0x96, 0xd9, 0x8f, 0x26, 0x4a }; - static const unsigned char SYNC2[] = { 0x55, 0x01, 0x00, 0x08, 0x34, 0x93, 0x49, 0xb4, 0x92, 0x4d, - 0x20, 0x26, 0x1b, 0x4d, 0xb4, 0xdb, 0xad, 0x76, 0x93 }; - static const unsigned char SYNC3[] = { 0x55, 0x01, 0x00, 0x06, 0x1b, 0x2c, 0xbf, 0x4b, 0x6d, 0xb6, - 0x4b, 0x18, 0x20, 0x92, 0x09, 0x20, 0xf2, 0x11, 0x2c }; - static const unsigned char SYNC4[] = { 0x55, 0x01, 0x00, 0x95, 0x29, 0x36, 0x91, 0x29, 0x36, 0x9a, - 0x69, 0x05, 0x2f, 0xbe, 0xdf, 0x6d, 0x16, 0xcb, 0xe7 }; - - static const unsigned char DOOR_CODE[] = { 0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe, - 0xfc, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x36, 0xb3 }; - - static const unsigned char LIGHT_CODE[] = { 0x55, 0x01, 0x00, 0x94, 0x3f, 0xef, 0xbc, 0xfb, 0x7f, 0xbe, - 0xff, 0xa6, 0x1a, 0x4d, 0xa6, 0xda, 0x8d, 0x76, 0xb1 }; - - static const int STARTUP_DELAY = 2000; // delay before enabling interrupts /*************************** DRY CONTACT CONTROL OF LIGHT & DOOR @@ -460,18 +443,6 @@ namespace ratgdo { this->pref_.save(&this->rollingCodeCounter); } - void RATGDOComponent::sendSyncCodes() - { - transmit(SYNC1); - delay(65); - transmit(SYNC2); - delay(65); - transmit(SYNC3); - delay(65); - transmit(SYNC4); - delay(65); - } - void RATGDOComponent::openDoor() { if(this->doorStates[this->store_.doorState] == "open" || doorStates[this->store_.doorState] == "opening"){ @@ -500,36 +471,40 @@ namespace ratgdo { void RATGDOComponent::toggleDoor() { - if (this->useRollingCodes_) { - getRollingCode("door1"); - transmit(this->txRollingCode); + getRollingCode("door1"); + transmit(this->txRollingCode); - delay(40); + delay(40); - getRollingCode("door2"); - transmit(this->txRollingCode); + getRollingCode("door2"); + transmit(this->txRollingCode); - this->pref_.save(&this->rollingCodeCounter); - } else { - sendSyncCodes(); - ESP_LOGD(TAG, "door_code"); - transmit(DOOR_CODE); - } + this->pref_.save(&this->rollingCodeCounter); + } - void RATGDOComponent::toggleLight() - { - if (this->useRollingCodes_) { - getRollingCode("light"); - transmit(this->txRollingCode); - this->pref_.save(&this->rollingCodeCounter); - } else { - sendSyncCodes(); - ESP_LOGD(TAG, "light_code"); - transmit(LIGHT_CODE); + void RATGDOComponent::lightOn(){ + if(his->lightStates[this->store_.lightState] == "on"){ + ESP_LOGD(TAG, "already on"); + }else{ + toggleLight(); } } + void RATGDOComponent::lightOff(){ + if(his->lightStates[this->store_.lightState] == "off"){ + ESP_LOGD(TAG, "already off"); + }else{ + toggleLight(); + } + } + + void RATGDOComponent::toggleLight(){ + getRollingCode("light"); + transmit(this->txRollingCode); + this->pref_.save(&this->rollingCodeCounter); + } + // Lock functions void RATGDOComponent::lock(){ if(this->lockStates[this->store_.lockState] == "locked"){ diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index a930812..3b782aa 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -97,10 +97,8 @@ namespace ratgdo { /********************************** FUNCTION DECLARATION * *****************************************/ - void set_rolling_codes(bool useRollingCodes); void transmit(const uint8_t*); void sync(); - void sendSyncCodes(); void obstructionLoop(); void sendObstructionStatus(); @@ -133,7 +131,6 @@ namespace ratgdo { protected: ESPPreferenceObject pref_; - bool useRollingCodes_ { true }; RATGDOStore store_ {}; InternalGPIOPin* output_gdo_pin_;