9static const char *
const TAG =
"feedback.cover";
16 if (restore.has_value()) {
24#ifdef USE_BINARY_SENSOR
45 traits.set_supports_stop(
true);
46 traits.set_supports_position(
true);
47 traits.set_supports_toggle(
true);
53 LOG_COVER(
"",
"Endstop Cover",
this);
54 ESP_LOGCONFIG(TAG,
" Open Duration: %.1fs", this->
open_duration_ / 1e3f);
55#ifdef USE_BINARY_SENSOR
60 ESP_LOGCONFIG(TAG,
" Close Duration: %.1fs", this->
close_duration_ / 1e3f);
61#ifdef USE_BINARY_SENSOR
67 ESP_LOGCONFIG(TAG,
" Has builtin endstop: YES");
70 ESP_LOGCONFIG(TAG,
" Infer endstop from movement: YES");
73 ESP_LOGCONFIG(TAG,
" Max Duration: %.1fs", this->
max_duration_ / 1e3f);
81#ifdef USE_BINARY_SENSOR
88#ifdef USE_BINARY_SENSOR
95 ESP_LOGD(TAG,
"'%s' - Open feedback '%s'.", this->
name_.
c_str(), state ?
"STARTED" :
"ENDED");
108 ESP_LOGD(TAG,
"'%s' - Close feedback '%s'.", this->
name_.
c_str(), state ?
"STARTED" :
"ENDED");
138 const uint32_t now =
millis();
146 ESP_LOGD(TAG,
"'%s' - %s endstop reached. Took %.1fs.", this->
name_.
c_str(), open_endstop ?
"Open" :
"Close", dur);
173#ifdef USE_BINARY_SENSOR
185#ifdef USE_BINARY_SENSOR
192 ESP_LOGD(TAG,
"'%s' - Close obstacle detected.", this->
name_.
c_str());
209 ESP_LOGD(TAG,
"'%s' - Open obstacle detected.", this->
name_.
c_str());
241 ESP_LOGD(TAG,
"'%s' - Max duration reached. Stopping cover.", this->
name_.
c_str());
257 if (
call.get_stop()) {
274 auto pos = *
call.get_position();
281#ifdef USE_BINARY_SENSOR
286#ifdef USE_BINARY_SENSOR
332#ifdef USE_BINARY_SENSOR
343#ifdef USE_BINARY_SENSOR
350#ifdef USE_BINARY_SENSOR
360#ifdef USE_BINARY_SENSOR
363 if (obstacle !=
nullptr && obstacle->state) {
364 ESP_LOGD(TAG,
"'%s' - %s obstacle detected. Action not started.", this->
name_.
c_str(),
374 ESP_LOGD(TAG,
"'%s' - Reversing direction.", this->
name_.
c_str());
383 ESP_LOGD(TAG,
"'%s' - Firing '%s' trigger.", this->
name_.
c_str(),
395 const uint32_t now =
millis();
411#ifdef USE_BINARY_SENSOR
423#ifdef USE_BINARY_SENSOR
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
constexpr const char * c_str() const
void stop_action()
Stop any action connected to this trigger.
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Base class for all binary_sensor-type classes.
bool state
The current reported state of the binary sensor.
void add_on_state_callback(std::function< void(bool)> &&callback)
Add a callback to be notified of state changes.
const optional< bool > & get_toggle() const
const optional< float > & get_position() const
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
optional< CoverRestoreState > restore_state_()
void publish_state(bool save=true)
Publish the current state of the cover.
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
cover::CoverTraits get_traits() override
cover::CoverOperation current_trigger_operation_
Trigger * prev_command_trigger_
binary_sensor::BinarySensor * open_endstop_
void start_direction_(cover::CoverOperation dir)
uint32_t update_interval_
void set_open_obstacle_sensor(binary_sensor::BinarySensor *open_obstacle)
void set_open_sensor(binary_sensor::BinarySensor *open_feedback)
void set_current_operation_(cover::CoverOperation operation, bool is_triggered)
binary_sensor::BinarySensor * close_endstop_
void set_close_endstop(binary_sensor::BinarySensor *close_endstop)
void stop_prev_trigger_()
optional< uint32_t > direction_change_waittime_
binary_sensor::BinarySensor * close_obstacle_
void set_close_obstacle_sensor(binary_sensor::BinarySensor *close_obstacle)
void control(const cover::CoverCall &call) override
binary_sensor::BinarySensor * open_feedback_
bool is_at_target_() const
bool has_built_in_endstop_
void dump_config() override
uint32_t acceleration_wait_time_
void recompute_position_()
void endstop_reached_(bool open_endstop)
void set_open_endstop(binary_sensor::BinarySensor *open_endstop)
cover::CoverOperation last_operation_
binary_sensor::BinarySensor * open_obstacle_
uint32_t last_recompute_time_
binary_sensor::BinarySensor * close_feedback_
uint32_t last_publish_time_
void set_close_sensor(binary_sensor::BinarySensor *close_feedback)
CoverOperation
Enum encoding the current operation of a cover.
@ COVER_OPERATION_OPENING
The cover is currently opening.
@ COVER_OPERATION_CLOSING
The cover is currently closing.
@ COVER_OPERATION_IDLE
The cover is currently idle (not moving)
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)