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) {
42 ESP_LOGW(TAG,
"'%s' - Unrecognized command %s", LOG_STR_ARG(this->
parent_->
get_log_name()), command);
79 ESP_LOGV(TAG,
" Command: STOP");
82 ESP_LOGV(TAG,
" Command: STOP_TILT");
85 if (traits.get_supports_position()) {
86 ESP_LOGV(TAG,
" Position: %.0f%%", *this->
position_ * 100.0f);
91 if (this->
tilt_.has_value()) {
92 ESP_LOGV(TAG,
" Tilt: %.0f%%", *this->
tilt_ * 100.0f);
94 if (this->
toggle_.has_value()) {
95 ESP_LOGV(TAG,
" Command: TOGGLE");
108 if (!traits.get_supports_position() &&
pos != COVER_OPEN &&
pos != COVER_CLOSED) {
109 ESP_LOGW(TAG,
"'%s': position unsupported", name);
112 ESP_LOGW(TAG,
"'%s': position %.2f out of range", name,
pos);
116 if (this->
tilt_.has_value()) {
118 if (!traits.get_supports_tilt()) {
119 ESP_LOGW(TAG,
"'%s': tilt unsupported", name);
122 ESP_LOGW(TAG,
"'%s': tilt %.2f out of range", name,
tilt);
126 if (this->
toggle_.has_value()) {
127 if (!traits.get_supports_toggle()) {
128 ESP_LOGW(TAG,
"'%s': toggle unsupported", name);
133 if (!traits.get_supports_stop_tilt()) {
134 ESP_LOGW(TAG,
"'%s': stop tilt unsupported", name);
136 }
else if (this->
tilt_.has_value()) {
137 ESP_LOGW(TAG,
"'%s': cannot tilt when stopping tilt", name);
142 if (this->
position_.has_value() || this->tilt_.has_value() || this->toggle_.has_value()) {
143 ESP_LOGW(TAG,
"'%s': cannot position/tilt/toggle when stopping", name);
160 this->
tilt = clamp(this->
tilt, 0.0f, 1.0f);
162 ESP_LOGV(TAG,
"'%s' >>", LOG_STR_ARG(this->
get_log_name()));
164 if (traits.get_supports_position()) {
165 ESP_LOGV(TAG,
" Position: %.0f%%", this->
position * 100.0f);
168 ESP_LOGV(TAG,
" State: OPEN");
169 }
else if (this->
position == COVER_CLOSED) {
170 ESP_LOGV(TAG,
" State: CLOSED");
172 ESP_LOGV(TAG,
" State: UNKNOWN");
175 if (traits.get_supports_tilt()) {
176 ESP_LOGV(TAG,
" Tilt: %.0f%%", this->
tilt * 100.0f);
181#if defined(USE_COVER) && defined(USE_CONTROLLER_REGISTRY)
182 ControllerRegistry::notify_cover_update(
this);
187 memset(&restore, 0,
sizeof(restore));
189 if (traits.get_supports_tilt()) {
190 restore.tilt = this->
tilt;
207 if (traits.get_supports_tilt())
208 call.set_tilt(this->
tilt);
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
ESPPreferenceObject make_entity_preference(uint32_t version=0)
Create a preference object for storing this entity's state/settings.
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.
CoverCall & set_stop_tilt(bool stop_tilt)
Set whether this cover call should stop the cover tilt.
optional< float > position_
CoverCall & set_command_stop_tilt()
Set the command to stop the cover tilt.
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)
ESPHOME_LOG_TAG(TAG, "cover")
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.