[switch] Add control() method to API (#10118)

This commit is contained in:
Edward Firmo
2025-08-08 05:51:19 +00:00
committed by GitHub
parent 7e4d09dbd8
commit 676c51ffa0
3 changed files with 17 additions and 5 deletions
+8
View File
@@ -8,6 +8,14 @@ static const char *const TAG = "switch";
Switch::Switch() : state(false) {}
void Switch::control(bool target_state) {
ESP_LOGV(TAG, "'%s' Control: %s", this->get_name().c_str(), ONOFF(target_state));
if (target_state) {
this->turn_on();
} else {
this->turn_off();
}
}
void Switch::turn_on() {
ESP_LOGD(TAG, "'%s' Turning ON.", this->get_name().c_str());
this->write_state(!this->inverted_);