diff --git a/components/ratgdo/switch/ratgdo_switch.cpp b/components/ratgdo/switch/ratgdo_switch.cpp index 8115630..a858fe1 100644 --- a/components/ratgdo/switch/ratgdo_switch.cpp +++ b/components/ratgdo/switch/ratgdo_switch.cpp @@ -17,16 +17,14 @@ namespace ratgdo { { this->state(state == LockState::LOCK_STATE_LOCKED) this->publish_state(); } - void RATGDOSwitch::turn_on() + void RATGDOSwitch::write_state(bool state) { - ESP_LOGD(TAG, "name: %s this->type_:%d ON", this->get_name(), this->switch_type_); - this->parent_->lock(value); - this->publish_state(value); - } - void RATGDOSwitch::turn_off() - { - ESP_LOGD(TAG, "name: %s this->type_:%d OFF", this->get_name(), this->switch_type_); - this->parent_->unlock(value); + 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); + } this->publish_state(value); } diff --git a/components/ratgdo/switch/ratgdo_switch.h b/components/ratgdo/switch/ratgdo_switch.h index b815818..aa6bbcd 100644 --- a/components/ratgdo/switch/ratgdo_switch.h +++ b/components/ratgdo/switch/ratgdo_switch.h @@ -19,8 +19,7 @@ namespace ratgdo { void set_switch_type(SwitchType switch_type_) { this->switch_type_ = switch_type_; } void on_lock_state(LockState state) override; - void turn_off() override; - void turn_on() override; + void write_state(bool state) override; protected: SwitchType switch_type_;