8static const char *
const TAG = 
"cover";
 
   39  if (strcasecmp(command, 
"OPEN") == 0) {
 
   41  } 
else if (strcasecmp(command, 
"CLOSE") == 0) {
 
   43  } 
else if (strcasecmp(command, 
"STOP") == 0) {
 
   45  } 
else if (strcasecmp(command, 
"TOGGLE") == 0) {
 
 
   81    ESP_LOGD(TAG, 
"  Command: STOP");
 
   84    if (traits.get_supports_position()) {
 
   85      ESP_LOGD(TAG, 
"  Position: %.0f%%", *this->
position_ * 100.0f);
 
   91    ESP_LOGD(TAG, 
"  Tilt: %.0f%%", *this->
tilt_ * 100.0f);
 
   94    ESP_LOGD(TAG, 
"  Command: TOGGLE");
 
 
  108      ESP_LOGW(TAG, 
"'%s': position unsupported", name);
 
  110    } 
else if (pos < 0.0f || pos > 1.0f) {
 
  111      ESP_LOGW(TAG, 
"'%s': position %.2f out of range", name, pos);
 
  112      this->
position_ = clamp(pos, 0.0f, 1.0f);
 
  117    if (!traits.get_supports_tilt()) {
 
  118      ESP_LOGW(TAG, 
"'%s': tilt unsupported", name);
 
  121      ESP_LOGW(TAG, 
"'%s': tilt %.2f out of range", name, 
tilt);
 
  126    if (!traits.get_supports_toggle()) {
 
  127      ESP_LOGW(TAG, 
"'%s': toggle unsupported", name);
 
  132    if (this->
position_.
has_value() || this->tilt_.has_value() || this->toggle_.has_value()) {
 
  133      ESP_LOGW(TAG, 
"'%s': cannot position/tilt/toggle when stopping", name);
 
 
  149  call.set_command_open();
 
  154  call.set_command_close();
 
  159  call.set_command_stop();
 
  165  this->
tilt = clamp(this->
tilt, 0.0f, 1.0f);
 
  167  ESP_LOGD(TAG, 
"'%s' - Publishing:", this->
name_.
c_str());
 
  169  if (traits.get_supports_position()) {
 
  170    ESP_LOGD(TAG, 
"  Position: %.0f%%", this->
position * 100.0f);
 
  173      ESP_LOGD(TAG, 
"  State: OPEN");
 
  174    } 
else if (this->
position == COVER_CLOSED) {
 
  175      ESP_LOGD(TAG, 
"  State: CLOSED");
 
  177      ESP_LOGD(TAG, 
"  State: UNKNOWN");
 
  180  if (traits.get_supports_tilt()) {
 
  181    ESP_LOGD(TAG, 
"  Tilt: %.0f%%", this->
tilt * 100.0f);
 
  189    memset(&restore, 0, 
sizeof(restore));
 
  191    if (traits.get_supports_tilt()) {
 
  192      restore.tilt = this->
tilt;
 
 
  212  if (traits.get_supports_tilt())
 
  213    call.set_tilt(this->
tilt);
 
 
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
 
const StringRef & get_name() const
 
uint32_t get_preference_hash()
Get a unique hash for storing preferences/settings for this entity.
 
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.
 
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....
 
CallbackManager< void()> state_callback_
 
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 char * cover_command_to_str(float pos)
 
const char * cover_operation_to_str(CoverOperation op)
 
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.
 
ESPPreferences * global_preferences
 
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.