50 lines
1.2 KiB
C++
Raw Normal View History

2023-12-18 12:56:25 -05:00
#include "ratgdo_switch.h"
#include "../ratgdo_state.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ratgdo {
static const char* const TAG = "ratgdo.switch";
void RATGDOSwitch::dump_config()
{
LOG_SWITCH("", "RATGDO Switch", this);
if (this->switch_type_ == SwitchType::RATGDO_LEARN) {
ESP_LOGCONFIG(TAG, " Type: Learn");
}
}
void RATGDOSwitch::setup()
{
if (this->switch_type_ == SwitchType::RATGDO_LEARN) {
this->parent_->subscribe_learn_state([=](LearnState state) {
this->on_learn_state(state);
});
}
}
void RATGDOSwitch::on_learn_state(LearnState state)
{
bool value = state == LearnState::ACTIVE;
this->state = value;
this->publish_state(value);
2023-12-22 14:12:20 -05:00
if (value == false) {
this->parent_->query_paired_devices();
}
2023-12-18 12:56:25 -05:00
}
void RATGDOSwitch::write_state(bool state)
{
if (this->switch_type_ == SwitchType::RATGDO_LEARN) {
if (state) {
this->parent_->activate_learn();
} else {
this->parent_->inactivate_learn();
}
}
}
} // namespace ratgdo
} // namespace esphome