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 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 diff --git a/components/ratgdo/dry_contact.cpp b/components/ratgdo/dry_contact.cpp index 8589a7c..c88263d 100644 --- a/components/ratgdo/dry_contact.cpp +++ b/components/ratgdo/dry_contact.cpp @@ -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 diff --git a/components/ratgdo/dry_contact.h b/components/ratgdo/dry_contact.h index dee045d..deba39e 100644 --- a/components/ratgdo/dry_contact.h +++ b/components/ratgdo/dry_contact.h @@ -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 diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 604b1e3..9983dbf 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -699,7 +699,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) { @@ -707,7 +707,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) { diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index ccb5b20..8da964f 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -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" @@ -94,8 +95,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); } @@ -183,8 +184,8 @@ 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_; + esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_; + esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_; }; // RATGDOComponent } // namespace ratgdo