ESPHome  2024.10.2
dfrobot_sen0395_switch.cpp
Go to the documentation of this file.
2 
3 namespace esphome {
4 namespace dfrobot_sen0395 {
5 
6 void Sen0395PowerSwitch::write_state(bool state) { this->parent_->enqueue(make_unique<PowerCommand>(state)); }
7 
9  bool was_active = false;
10  if (this->parent_->is_active()) {
11  was_active = true;
12  this->parent_->enqueue(make_unique<PowerCommand>(false));
13  }
14  this->parent_->enqueue(make_unique<LedModeCommand>(state));
15  this->parent_->enqueue(make_unique<SaveCfgCommand>());
16  if (was_active) {
17  this->parent_->enqueue(make_unique<PowerCommand>(true));
18  }
19 }
20 
22  bool was_active = false;
23  if (this->parent_->is_active()) {
24  was_active = true;
25  this->parent_->enqueue(make_unique<PowerCommand>(false));
26  }
27  this->parent_->enqueue(make_unique<UartOutputCommand>(state));
28  this->parent_->enqueue(make_unique<SaveCfgCommand>());
29  if (was_active) {
30  this->parent_->enqueue(make_unique<PowerCommand>(true));
31  }
32 }
33 
35  bool was_active = false;
36  if (this->parent_->is_active()) {
37  was_active = true;
38  this->parent_->enqueue(make_unique<PowerCommand>(false));
39  }
40  this->parent_->enqueue(make_unique<SensorCfgStartCommand>(state));
41  this->parent_->enqueue(make_unique<SaveCfgCommand>());
42  if (was_active) {
43  this->parent_->enqueue(make_unique<PowerCommand>(true));
44  }
45 }
46 
47 } // namespace dfrobot_sen0395
48 } // namespace esphome
DfrobotSen0395Component * parent_
Definition: helpers.h:532
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool state
The current reported state of the binary sensor.
Definition: switch.h:53
bool state
Definition: fan.h:34