2024-01-18 22:25:08 +00: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) {
|
2024-01-19 23:24:16 +00:00
|
|
|
this->publish_state(state == LearnState::ACTIVE);
|
2024-01-18 22:25:08 +00:00
|
|
|
});
|
2024-11-10 18:05:29 +00:00
|
|
|
} else if (this->switch_type_ == SwitchType::RATGDO_LED) {
|
2024-10-28 17:56:16 +00:00
|
|
|
this->pin_->setup();
|
|
|
|
this->parent_->subscribe_vehicle_arriving_state([=](VehicleArrivingState state) {
|
|
|
|
this->write_state(state == VehicleArrivingState::YES);
|
|
|
|
});
|
2024-01-18 22:25:08 +00: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();
|
|
|
|
}
|
2024-11-10 18:05:29 +00:00
|
|
|
} else if (this->switch_type_ == SwitchType::RATGDO_LED) {
|
2024-10-28 17:56:16 +00:00
|
|
|
this->pin_->digital_write(state);
|
|
|
|
this->publish_state(state);
|
2024-01-18 22:25:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ratgdo
|
|
|
|
} // namespace esphome
|