ESPHome 2025.5.0
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 {
5namespace copy {
6
7static const char *const TAG = "copy.cover";
8
12 this->position = this->source_->position;
13 this->tilt = this->source_->tilt;
14 this->publish_state();
15 });
16
18 this->position = this->source_->position;
19 this->tilt = this->source_->tilt;
20 this->publish_state();
21}
22
23void CopyCover::dump_config() { LOG_COVER("", "Copy Cover", this); }
24
26 auto base = source_->get_traits();
27 cover::CoverTraits traits{};
28 // copy traits manually so it doesn't break when new options are added
29 // but the control() method hasn't implemented them yet.
30 traits.set_is_assumed_state(base.get_is_assumed_state());
31 traits.set_supports_stop(base.get_supports_stop());
32 traits.set_supports_position(base.get_supports_position());
33 traits.set_supports_tilt(base.get_supports_tilt());
34 traits.set_supports_toggle(base.get_supports_toggle());
35 return traits;
36}
37
39 auto call2 = source_->make_call();
40 call2.set_stop(call.get_stop());
41 if (call.get_tilt().has_value())
42 call2.set_tilt(*call.get_tilt());
43 if (call.get_position().has_value())
44 call2.set_position(*call.get_position());
45 if (call.get_tilt().has_value())
46 call2.set_tilt(*call.get_tilt());
47 call2.perform();
48}
49
50} // namespace copy
51} // namespace esphome
cover::CoverTraits get_traits() override
void control(const cover::CoverCall &call) override
void setup() override
Definition copy_cover.cpp:9
void dump_config() override
cover::Cover * source_
Definition copy_cover.h:21
void perform()
Perform the cover call.
Definition cover.cpp:75
CoverCall & set_position(float position)
Set the call to a certain target position.
Definition cover.cpp:67
CoverCall & set_tilt(float tilt)
Set the call to a certain target tilt.
Definition cover.cpp:71
CoverCall & set_stop(bool stop)
Set whether this cover call should stop the cover.
Definition cover.cpp:143
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
Definition cover.h:116
void publish_state(bool save=true)
Publish the current state of the cover.
Definition cover.cpp:166
void add_on_state_callback(std::function< void()> &&f)
Definition cover.cpp:165
CoverCall make_call()
Construct a new cover call used to control the cover.
Definition cover.cpp:149
float tilt
The current tilt value of the cover from 0.0 to 1.0.
Definition cover.h:124
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
Definition cover.h:122
virtual CoverTraits get_traits()=0
void set_is_assumed_state(bool is_assumed_state)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7