ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
copy_cover.cpp
Go to the documentation of this file.
1#include "copy_cover.h"
2#include "esphome/core/log.h"
3
4namespace esphome::copy {
5
6static const char *const TAG = "copy.cover";
7
11 this->position = this->source_->position;
12 this->tilt = this->source_->tilt;
13 this->publish_state();
14 });
15
17 this->position = this->source_->position;
18 this->tilt = this->source_->tilt;
19 this->publish_state();
20}
21
22void CopyCover::dump_config() { LOG_COVER("", "Copy Cover", this); }
23
25 auto base = source_->get_traits();
26 cover::CoverTraits traits{};
27 // copy traits manually so it doesn't break when new options are added
28 // but the control() method hasn't implemented them yet.
29 traits.set_is_assumed_state(base.get_is_assumed_state());
30 traits.set_supports_stop(base.get_supports_stop());
31 traits.set_supports_position(base.get_supports_position());
32 traits.set_supports_tilt(base.get_supports_tilt());
33 traits.set_supports_toggle(base.get_supports_toggle());
34 return traits;
35}
36
38 auto call2 = source_->make_call();
39 call2.set_stop(call.get_stop());
40 auto tilt = call.get_tilt();
41 if (tilt.has_value())
42 call2.set_tilt(*tilt);
43 auto position = call.get_position();
44 if (position.has_value())
45 call2.set_position(*position);
46 auto tilt2 = call.get_tilt();
47 if (tilt2.has_value())
48 call2.set_tilt(*tilt2);
49 call2.perform();
50}
51
52} // namespace esphome::copy
cover::CoverTraits get_traits() override
void control(const cover::CoverCall &call) override
void setup() override
Definition copy_cover.cpp:8
void dump_config() override
cover::Cover * source_
Definition copy_cover.h:19
const optional< float > & get_tilt() const
Definition cover.cpp:93
CoverCall & set_stop(bool stop)
Set whether this cover call should stop the cover.
Definition cover.cpp:134
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
Definition cover.h:115
void add_on_state_callback(F &&f)
Definition cover.h:128
void publish_state(bool save=true)
Publish the current state of the cover.
Definition cover.cpp:142
CoverCall make_call()
Construct a new cover call used to control the cover.
Definition cover.cpp:140
float tilt
The current tilt value of the cover from 0.0 to 1.0.
Definition cover.h:123
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
Definition cover.h:121
virtual CoverTraits get_traits()=0
void set_is_assumed_state(bool is_assumed_state)