8namespace current_based {
10static const char *
const TAG =
"current_based.cover";
16 traits.set_supports_stop(
true);
17 traits.set_supports_position(
true);
18 traits.set_supports_toggle(
true);
19 traits.set_is_assumed_state(
false);
23 if (
call.get_stop()) {
41 auto pos = *
call.get_position();
42 if (fabsf(this->
position - pos) < 0.01) {
53 if (restore.has_value()) {
70 ESP_LOGI(TAG,
"'%s' - Malfunction detected during opening. Current flow detected in close circuit",
73 ESP_LOGD(TAG,
"'%s' - Obstacle detected during opening.", this->
name_.
c_str());
77 ESP_LOGD(TAG,
"'%s' - Rollback.", this->
name_.
c_str());
84 ESP_LOGD(TAG,
"'%s' - Open position reached. Took %.1fs.", this->
name_.
c_str(), dur);
91 ESP_LOGI(TAG,
"'%s' - Malfunction detected during closing. Current flow detected in open circuit",
94 ESP_LOGD(TAG,
"'%s' - Obstacle detected during closing.", this->
name_.
c_str());
98 ESP_LOGD(TAG,
"'%s' - Rollback.", this->
name_.
c_str());
105 ESP_LOGD(TAG,
"'%s' - Close position reached. Took %.1fs.", this->
name_.
c_str(), dur);
110 ESP_LOGD(TAG,
"'%s' - Max duration reached. Stopping cover.", this->
name_.
c_str());
130 if (new_position != FLT_MAX) {
137 LOG_COVER(
"",
"Endstop Cover",
this);
143 ESP_LOGCONFIG(TAG,
" Open Duration: %.1fs", this->
open_duration_ / 1e3f);
149 ESP_LOGCONFIG(TAG,
" Close Duration: %.1fs", this->
close_duration_ / 1e3f);
152 ESP_LOGCONFIG(TAG,
"Maximum duration: %.1fs", this->
max_duration_ / 1e3f);
240 const auto now =
millis();
263 const auto now =
millis();
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.
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.
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).
float close_moving_current_threshold_
sensor::Sensor * close_sensor_
void start_direction_(cover::CoverOperation dir)
float open_obstacle_current_threshold_
void recompute_position_()
bool is_closing_blocked_() const
Trigger * prev_command_trigger_
float get_setup_priority() const override
bool is_at_target_() const
uint32_t last_publish_time_
float open_moving_current_threshold_
float close_obstacle_current_threshold_
bool is_initial_delay_finished_() const
cover::CoverTraits get_traits() override
bool is_opening_blocked_() const
uint32_t start_sensing_delay_
void dump_config() override
void control(const cover::CoverCall &call) override
cover::CoverOperation last_operation_
Trigger * malfunction_trigger_
bool malfunction_detection_
void stop_prev_trigger_()
uint32_t last_recompute_time_
void direction_idle_(float new_position=FLT_MAX)
sensor::Sensor * open_sensor_
float get_state() const
Getter-syntax for .state.
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)
const float DATA
For components that import data from directly connected sensors like DHT.
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)