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_LOGD(TAG,
" Command: STOP");
78 if (traits.get_supports_position()) {
79 ESP_LOGD(TAG,
" Position: %.0f%%", *this->
position_ * 100.0f);
85 ESP_LOGD(TAG,
" Tilt: %.0f%%", *this->
tilt_ * 100.0f);
88 ESP_LOGD(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);
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);
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);
145 this->
tilt = clamp(this->
tilt, 0.0f, 1.0f);
147 ESP_LOGD(TAG,
"'%s' >>", this->
name_.
c_str());
149 if (traits.get_supports_position()) {
150 ESP_LOGD(TAG,
" Position: %.0f%%", this->
position * 100.0f);
153 ESP_LOGD(TAG,
" State: OPEN");
154 }
else if (this->
position == COVER_CLOSED) {
155 ESP_LOGD(TAG,
" State: CLOSED");
157 ESP_LOGD(TAG,
" State: UNKNOWN");
160 if (traits.get_supports_tilt()) {
161 ESP_LOGD(TAG,
" Tilt: %.0f%%", this->
tilt * 100.0f);
166#if defined(USE_COVER) && defined(USE_CONTROLLER_REGISTRY)
172 memset(&restore, 0,
sizeof(restore));
174 if (traits.get_supports_tilt()) {
175 restore.tilt = this->
tilt;
195 if (traits.get_supports_tilt())
196 call.set_tilt(this->
tilt);
static void notify_cover_update(cover::Cover *obj)
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.
void add_on_state_callback(std::function< void()> &&f)
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).
bool is_fully_closed() const
Helper method to check if the cover is fully closed. Equivalent to comparing .position against 0....
virtual CoverTraits get_traits()=0
bool is_fully_open() const
Helper method to check if the cover is fully open. Equivalent to comparing .position against 1....
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.