11static const char *
const TAG =
"cover";
14 if (
pos == COVER_OPEN) {
15 return LOG_STR(
"OPEN");
16 }
else if (
pos == COVER_CLOSED) {
17 return LOG_STR(
"CLOSE");
19 return LOG_STR(
"UNKNOWN");
26 return CoverOperationStrings::get_log_str(
static_cast<uint8_t
>(op), CoverOperationStrings::LAST_INDEX);
33 if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR(
"OPEN")) == 0) {
35 }
else if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR(
"CLOSE")) == 0) {
37 }
else if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR(
"STOP")) == 0) {
39 }
else if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR(
"TOGGLE")) == 0) {
75 ESP_LOGV(TAG,
" Command: STOP");
78 if (traits.get_supports_position()) {
79 ESP_LOGV(TAG,
" Position: %.0f%%", *this->
position_ * 100.0f);
84 if (this->
tilt_.has_value()) {
85 ESP_LOGV(TAG,
" Tilt: %.0f%%", *this->
tilt_ * 100.0f);
87 if (this->
toggle_.has_value()) {
88 ESP_LOGV(TAG,
" Command: TOGGLE");
101 if (!traits.get_supports_position() &&
pos != COVER_OPEN &&
pos != COVER_CLOSED) {
102 ESP_LOGW(TAG,
"'%s': position unsupported", name);
105 ESP_LOGW(TAG,
"'%s': position %.2f out of range", name,
pos);
109 if (this->
tilt_.has_value()) {
111 if (!traits.get_supports_tilt()) {
112 ESP_LOGW(TAG,
"'%s': tilt unsupported", name);
115 ESP_LOGW(TAG,
"'%s': tilt %.2f out of range", name,
tilt);
119 if (this->
toggle_.has_value()) {
120 if (!traits.get_supports_toggle()) {
121 ESP_LOGW(TAG,
"'%s': toggle unsupported", name);
126 if (this->
position_.has_value() || this->tilt_.has_value() || this->toggle_.has_value()) {
127 ESP_LOGW(TAG,
"'%s': cannot position/tilt/toggle when stopping", name);
140 this->
tilt = clamp(this->
tilt, 0.0f, 1.0f);
142 ESP_LOGV(TAG,
"'%s' >>", this->
name_.
c_str());
144 if (traits.get_supports_position()) {
145 ESP_LOGV(TAG,
" Position: %.0f%%", this->
position * 100.0f);
148 ESP_LOGV(TAG,
" State: OPEN");
149 }
else if (this->
position == COVER_CLOSED) {
150 ESP_LOGV(TAG,
" State: CLOSED");
152 ESP_LOGV(TAG,
" State: UNKNOWN");
155 if (traits.get_supports_tilt()) {
156 ESP_LOGV(TAG,
" Tilt: %.0f%%", this->
tilt * 100.0f);
161#if defined(USE_COVER) && defined(USE_CONTROLLER_REGISTRY)
162 ControllerRegistry::notify_cover_update(
this);
167 memset(&restore, 0,
sizeof(restore));
169 if (traits.get_supports_tilt()) {
170 restore.tilt = this->
tilt;
187 if (traits.get_supports_tilt())
188 call.set_tilt(this->
tilt);
const StringRef & get_name() const
ESPPreferenceObject make_entity_preference(uint32_t version=0)
Create a preference object for storing this entity's state/settings.
constexpr const char * c_str() const
const optional< float > & get_tilt() const
CoverCall & set_command_toggle()
Set the command to toggle the cover.
const optional< bool > & get_toggle() const
CoverCall & set_command_open()
Set the command to open the cover.
CoverCall & set_command_close()
Set the command to close the cover.
CoverCall & set_command(const char *command)
Set the command as a string, "STOP", "OPEN", "CLOSE", "TOGGLE".
void perform()
Perform the cover call.
CoverCall & set_position(float position)
Set the call to a certain target position.
CoverCall & set_command_stop()
Set the command to stop the cover.
optional< float > position_
const optional< float > & get_position() const
CoverCall & set_tilt(float tilt)
Set the call to a certain target tilt.
CoverCall & set_stop(bool stop)
Set whether this cover call should stop the cover.
Base class for all cover devices.
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.
CoverCall make_call()
Construct a new cover call used to control the cover.
LazyCallbackManager< void()> state_callback_
float tilt
The current tilt value of the cover from 0.0 to 1.0.
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
virtual CoverTraits get_traits()=0
virtual void control(const CoverCall &call)=0
const LogString * cover_operation_to_str(CoverOperation op)
const LogString * cover_command_to_str(float pos)
CoverOperation
Enum encoding the current operation of a cover.
PROGMEM_STRING_TABLE(CoverOperationStrings, "IDLE", "OPENING", "CLOSING", "UNKNOWN")
Struct used to store the restored state of a cover.
void apply(Cover *cover)
Apply these settings to the cover.
CoverCall to_call(Cover *cover)
Convert this struct to a cover call that can be performed.