esphome-ratgdo/components/ratgdo/switch/ratgdo_switch.cpp

33 lines
737 B
C++
Raw Normal View History

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;
2023-06-09 21:00:25 +00:00
this->state = value;
2023-06-09 21:00:42 +00:00
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
if (state) {
2023-06-09 21:00:09 +00:00
this->parent_->lock();
2023-06-09 20:58:55 +00:00
} else {
2023-06-09 21:00:09 +00:00
this->parent_->unlock();
2023-06-09 20:58:55 +00:00
}
2023-06-09 20:54:20 +00:00
}
} // namespace ratgdo
} // namespace esphome