2023-06-09 20:54:20 +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()
|
|
|
|
{
|
2023-06-09 20:56:13 +00:00
|
|
|
LOG_SWITCH("", "RATGDO Switch", this);
|
2023-06-09 20:54:20 +00:00
|
|
|
ESP_LOGCONFIG(TAG, " Type: Lock");
|
|
|
|
}
|
|
|
|
|
|
|
|
void RATGDOSwitch::on_lock_state(LockState state)
|
|
|
|
{
|
2023-06-09 21:00:00 +00:00
|
|
|
bool value = state == LockState::LOCK_STATE_LOCKED;
|
|
|
|
this->state(value);
|
|
|
|
this->publish_state(value);
|
2023-06-09 20:54:20 +00:00
|
|
|
}
|
2023-06-09 20:58:55 +00:00
|
|
|
void RATGDOSwitch::write_state(bool state)
|
2023-06-09 20:54:20 +00:00
|
|
|
{
|
2023-06-09 20:58:55 +00:00
|
|
|
ESP_LOGD(TAG, "name: %s this->type_:%d state: %d", this->get_name(), this->switch_type_, state);
|
|
|
|
if (state) {
|
|
|
|
this->parent_->lock(value);
|
|
|
|
} else {
|
|
|
|
this->parent_->unlock(value);
|
|
|
|
}
|
2023-06-09 20:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ratgdo
|
|
|
|
} // namespace esphome
|