ESPHome 2026.11.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
6ESPHOME_LOG_TAG(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 traits.set_supports_stop_tilt(base.get_supports_stop_tilt());
35 return traits;
36}
37
39 auto call2 = source_->make_call();
40 call2.set_stop(call.get_stop());
41 call2.set_stop_tilt(call.get_stop_tilt());
42 auto tilt = call.get_tilt();
43 if (tilt.has_value())
44 call2.set_tilt(*tilt);
45 auto position = call.get_position();
46 if (position.has_value())
47 call2.set_position(*position);
48 auto tilt2 = call.get_tilt();
49 if (tilt2.has_value())
50 call2.set_tilt(*tilt2);
51 call2.perform();
52}
53
54} // 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:100
CoverCall & set_stop_tilt(bool stop_tilt)
Set whether this cover call should stop the cover tilt.
Definition cover.cpp:154
CoverCall & set_stop(bool stop)
Set whether this cover call should stop the cover.
Definition cover.cpp:150
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
Definition cover.h:120
void add_on_state_callback(F &&f)
Definition cover.h:133
void publish_state(bool save=true)
Publish the current state of the cover.
Definition cover.cpp:158
CoverCall make_call()
Construct a new cover call used to control the cover.
Definition cover.h:131
float tilt
The current tilt value of the cover from 0.0 to 1.0.
Definition cover.h:128
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
Definition cover.h:126
virtual CoverTraits get_traits()=0
void set_is_assumed_state(bool is_assumed_state)
ESPHOME_LOG_TAG(TAG, "copy.binary_sensor")