Update with main (#303)

This commit is contained in:
Paul Wieland 2024-07-11 16:45:08 -04:00 committed by GitHub
parent cdcc8bacaf
commit 0fb13fc547
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 34 additions and 14 deletions

View File

@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks # See https://pre-commit.com/hooks.html for more hooks
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0 rev: v4.6.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: end-of-file-fixer - id: end-of-file-fixer

View File

@ -18,9 +18,13 @@ CoverOpeningTrigger = ratgdo_ns.class_(
CoverClosingTrigger = ratgdo_ns.class_( CoverClosingTrigger = ratgdo_ns.class_(
"CoverClosingTrigger", automation.Trigger.template() "CoverClosingTrigger", automation.Trigger.template()
) )
CoverStateTrigger = ratgdo_ns.class_(
"CoverStateTrigger", automation.Trigger.template()
)
CONF_ON_OPENING = "on_opening" CONF_ON_OPENING = "on_opening"
CONF_ON_CLOSING = "on_closing" CONF_ON_CLOSING = "on_closing"
CONF_ON_STATE_CHANGE = "on_state_change"
CONFIG_SCHEMA = cover.COVER_SCHEMA.extend( 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.Optional(CONF_ON_CLOSING): automation.validate_automation(
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CoverClosingTrigger)} {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) ).extend(RATGDO_CLIENT_SCHMEA)
@ -46,5 +53,8 @@ async def to_code(config):
for conf in config.get(CONF_ON_CLOSING, []): for conf in config.get(CONF_ON_CLOSING, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var) trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf) 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) await register_ratgdo_child(var, config)

View File

@ -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 ratgdo
} // namespace esphome } // namespace esphome

View File

@ -1,11 +1,9 @@
#include "dry_contact.h" #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/gpio.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/scheduler.h" #include "esphome/core/scheduler.h"
#include "ratgdo.h"
namespace esphome { namespace esphome {
namespace ratgdo { namespace ratgdo {
@ -128,6 +126,6 @@ namespace ratgdo {
return {}; return {};
} }
} // namespace DryContact } // namespace dry_contact
} // namespace ratgdo } // namespace ratgdo
} // namespace esphome } // namespace esphome

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include "esphome/core/defines.h"
#include "SoftwareSerial.h" // Using espsoftwareserial https://github.com/plerup/espsoftwareserial #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/gpio.h"
#include "esphome/core/optional.h" #include "esphome/core/optional.h"
@ -72,6 +73,6 @@ namespace ratgdo {
bool last_close_limit_; bool last_close_limit_;
}; };
} // namespace secplus1 } // namespace dry_contact
} // namespace ratgdo } // namespace ratgdo
} // namespace esphome } // namespace esphome

View File

@ -699,7 +699,7 @@ namespace ratgdo {
} }
// dry contact methods // 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_ = dry_contact_open_sensor;
dry_contact_open_sensor_->add_on_state_callback([this](bool sensor_value) { 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_ = dry_contact_close_sensor;
dry_contact_close_sensor_->add_on_state_callback([this](bool sensor_value) { dry_contact_close_sensor_->add_on_state_callback([this](bool sensor_value) {

View File

@ -13,8 +13,9 @@
#pragma once #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/component.h"
#include "esphome/core/defines.h"
#include "esphome/core/hal.h" #include "esphome/core/hal.h"
#include "esphome/core/preferences.h" #include "esphome/core/preferences.h"
@ -94,8 +95,8 @@ namespace ratgdo {
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; } void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; }
// dry contact methods // dry contact methods
void set_dry_contact_open_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_); void set_dry_contact_open_sensor(esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_);
void set_dry_contact_close_sensor(esphome::gpio::GPIOBinarySensor* dry_contact_close_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_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); } 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* output_gdo_pin_;
InternalGPIOPin* input_gdo_pin_; InternalGPIOPin* input_gdo_pin_;
InternalGPIOPin* input_obst_pin_; InternalGPIOPin* input_obst_pin_;
esphome::gpio::GPIOBinarySensor* dry_contact_open_sensor_; esphome::binary_sensor::BinarySensor* dry_contact_open_sensor_;
esphome::gpio::GPIOBinarySensor* dry_contact_close_sensor_; esphome::binary_sensor::BinarySensor* dry_contact_close_sensor_;
}; // RATGDOComponent }; // RATGDOComponent
} // namespace ratgdo } // namespace ratgdo