[switch] Add control() method to API (#10118)
This commit is contained in:
1 parent
7e4d09dbd8
commit
676c51ffa0
3 files changed
+17
-5
No files matched your search
@@ -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_);
|
||||
|
||||
Reference in new issue
Block a user