From 9df4cebd539fa75a7a9a7e50b11e8ef674415acf Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Wed, 3 Jul 2024 09:34:57 -0400 Subject: [PATCH 1/4] Improve compatibility for non-dry-contact configurations. (#265) --- components/ratgdo/dry_contact.cpp | 9 ++++++--- components/ratgdo/dry_contact.h | 9 +++++++-- components/ratgdo/ratgdo.cpp | 6 ++++-- components/ratgdo/ratgdo.h | 17 ++++++++++++----- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/components/ratgdo/dry_contact.cpp b/components/ratgdo/dry_contact.cpp index 8589a7c..282d7b0 100644 --- a/components/ratgdo/dry_contact.cpp +++ b/components/ratgdo/dry_contact.cpp @@ -1,8 +1,9 @@ -#include "dry_contact.h" #include "ratgdo.h" -#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h" +#ifdef PROTOCOL_DRYCONTACT + +#include "dry_contact.h" #include "esphome/core/gpio.h" #include "esphome/core/log.h" #include "esphome/core/scheduler.h" @@ -128,6 +129,8 @@ namespace ratgdo { return {}; } - } // namespace DryContact + } // namespace dry_contact } // namespace ratgdo } // namespace esphome + +#endif diff --git a/components/ratgdo/dry_contact.h b/components/ratgdo/dry_contact.h index dee045d..60fa729 100644 --- a/components/ratgdo/dry_contact.h +++ b/components/ratgdo/dry_contact.h @@ -1,7 +1,10 @@ #pragma once +#include "esphome/core/defines.h" + +#ifdef PROTOCOL_DRYCONTACT + #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 +75,8 @@ namespace ratgdo { bool last_close_limit_; }; - } // namespace secplus1 + } // namespace dry_contact } // namespace ratgdo } // namespace esphome + +#endif diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 0327658..16c8e2a 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -680,8 +680,9 @@ namespace ratgdo { this->learn_state.subscribe([=](LearnState state) { defer("learn_state", [=] { f(state); }); }); } +#ifdef PROTOCOL_DRYCONTACT // 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) { @@ -689,13 +690,14 @@ 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) { this->protocol_->set_close_limit(sensor_value); }); } +#endif } // namespace ratgdo } // namespace esphome diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 4f9611d..c26ee43 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -13,10 +13,13 @@ #pragma once -#include "esphome/components/gpio/binary_sensor/gpio_binary_sensor.h" #include "esphome/core/component.h" +#include "esphome/core/defines.h" #include "esphome/core/hal.h" #include "esphome/core/preferences.h" +#ifdef PROTOCOL_DRYCONTACT +#include "esphome/components/binary_sensor/binary_sensor.h" +#endif #include "callbacks.h" #include "macros.h" @@ -92,11 +95,13 @@ namespace ratgdo { void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; } void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; } +#ifdef PROTOCOL_DRYCONTACT // 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); } +#endif Result call_protocol(Args args); @@ -181,8 +186,10 @@ namespace ratgdo { 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_; +#ifdef PROTOCOL_DRYCONTACT + esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_; + esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_; +#endif }; // RATGDOComponent } // namespace ratgdo From 38d2508edc148bbff816bfa9fdbb5ed3a6197549 Mon Sep 17 00:00:00 2001 From: Brendan Davis <4007825+brgaulin@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:03:24 -0400 Subject: [PATCH 2/4] feat: add cover.on_state_change trigger (#195) Co-authored-by: J. Nick Koston --- components/ratgdo/cover/__init__.py | 10 ++++++++++ components/ratgdo/cover/automation.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/components/ratgdo/cover/__init__.py b/components/ratgdo/cover/__init__.py index eb0f82f..ea8ba1e 100644 --- a/components/ratgdo/cover/__init__.py +++ b/components/ratgdo/cover/__init__.py @@ -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) diff --git a/components/ratgdo/cover/automation.h b/components/ratgdo/cover/automation.h index 93f103f..e8a1b38 100644 --- a/components/ratgdo/cover/automation.h +++ b/components/ratgdo/cover/automation.h @@ -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 From 9fc5cc45108d66395fad8a328c9e1ac57acbbc0d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 3 Jul 2024 08:41:59 -0700 Subject: [PATCH 3/4] Revert ifdefs added in #265 (#300) --- components/ratgdo/dry_contact.cpp | 7 +------ components/ratgdo/dry_contact.h | 4 ---- components/ratgdo/ratgdo.cpp | 2 -- components/ratgdo/ratgdo.h | 8 +------- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/components/ratgdo/dry_contact.cpp b/components/ratgdo/dry_contact.cpp index 282d7b0..c88263d 100644 --- a/components/ratgdo/dry_contact.cpp +++ b/components/ratgdo/dry_contact.cpp @@ -1,12 +1,9 @@ -#include "ratgdo.h" - -#ifdef PROTOCOL_DRYCONTACT - #include "dry_contact.h" #include "esphome/core/gpio.h" #include "esphome/core/log.h" #include "esphome/core/scheduler.h" +#include "ratgdo.h" namespace esphome { namespace ratgdo { @@ -132,5 +129,3 @@ namespace ratgdo { } // namespace dry_contact } // namespace ratgdo } // namespace esphome - -#endif diff --git a/components/ratgdo/dry_contact.h b/components/ratgdo/dry_contact.h index 60fa729..deba39e 100644 --- a/components/ratgdo/dry_contact.h +++ b/components/ratgdo/dry_contact.h @@ -2,8 +2,6 @@ #include "esphome/core/defines.h" -#ifdef PROTOCOL_DRYCONTACT - #include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial #include "esphome/core/gpio.h" #include "esphome/core/optional.h" @@ -78,5 +76,3 @@ namespace ratgdo { } // namespace dry_contact } // namespace ratgdo } // namespace esphome - -#endif diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 16c8e2a..90cb713 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -680,7 +680,6 @@ namespace ratgdo { this->learn_state.subscribe([=](LearnState state) { defer("learn_state", [=] { f(state); }); }); } -#ifdef PROTOCOL_DRYCONTACT // dry contact methods void RATGDOComponent::set_dry_contact_open_sensor(esphome::binary_sensor::BinarySensor* dry_contact_open_sensor) { @@ -697,7 +696,6 @@ namespace ratgdo { this->protocol_->set_close_limit(sensor_value); }); } -#endif } // namespace ratgdo } // namespace esphome diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index c26ee43..228d5bc 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -13,13 +13,11 @@ #pragma once +#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" -#ifdef PROTOCOL_DRYCONTACT -#include "esphome/components/binary_sensor/binary_sensor.h" -#endif #include "callbacks.h" #include "macros.h" @@ -95,13 +93,11 @@ namespace ratgdo { void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; } void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; } -#ifdef PROTOCOL_DRYCONTACT // dry contact methods 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); } -#endif Result call_protocol(Args args); @@ -186,10 +182,8 @@ namespace ratgdo { InternalGPIOPin* output_gdo_pin_; InternalGPIOPin* input_gdo_pin_; InternalGPIOPin* input_obst_pin_; -#ifdef PROTOCOL_DRYCONTACT esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_; esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_; -#endif }; // RATGDOComponent } // namespace ratgdo From 88b3bdf5ff27cb3880795dacf824e1c10697a2b3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Jul 2024 13:57:21 -0700 Subject: [PATCH 4/4] [pre-commit.ci] pre-commit autoupdate (#302) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v3.2.0 → v4.6.0](https://github.com/pre-commit/pre-commit-hooks/compare/v3.2.0...v4.6.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b1339ac..a0b1611 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer