esphome/esphome/components/copy/switch/copy_switch.cpp
2022-02-21 09:13:37 +13:00

26 lines
541 B
C++

#include "copy_switch.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.switch";
void CopySwitch::setup() {
source_->add_on_state_callback([this](float value) { this->publish_state(value); });
this->publish_state(source_->state);
}
void CopySwitch::dump_config() { LOG_SWITCH("", "Copy Switch", this); }
void CopySwitch::write_state(bool state) {
if (state) {
source_->turn_on();
} else {
source_->turn_off();
}
}
} // namespace copy
} // namespace esphome