ESPHome  2024.10.2
automation.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/helpers.h"
5 
6 #include "dfrobot_sen0395.h"
7 
8 namespace esphome {
9 namespace dfrobot_sen0395 {
10 
11 template<typename... Ts>
12 class DfrobotSen0395ResetAction : public Action<Ts...>, public Parented<DfrobotSen0395Component> {
13  public:
14  void play(Ts... x) { this->parent_->enqueue(make_unique<ResetSystemCommand>()); }
15 };
16 
17 template<typename... Ts>
18 class DfrobotSen0395SettingsAction : public Action<Ts...>, public Parented<DfrobotSen0395Component> {
19  public:
20  TEMPLATABLE_VALUE(int8_t, factory_reset)
21  TEMPLATABLE_VALUE(int8_t, start_after_power_on)
22  TEMPLATABLE_VALUE(int8_t, turn_on_led)
23  TEMPLATABLE_VALUE(int8_t, presence_via_uart)
24  TEMPLATABLE_VALUE(int8_t, sensitivity)
25  TEMPLATABLE_VALUE(float, delay_after_detect)
26  TEMPLATABLE_VALUE(float, delay_after_disappear)
27  TEMPLATABLE_VALUE(float, det_min1)
28  TEMPLATABLE_VALUE(float, det_max1)
29  TEMPLATABLE_VALUE(float, det_min2)
30  TEMPLATABLE_VALUE(float, det_max2)
31  TEMPLATABLE_VALUE(float, det_min3)
32  TEMPLATABLE_VALUE(float, det_max3)
33  TEMPLATABLE_VALUE(float, det_min4)
34  TEMPLATABLE_VALUE(float, det_max4)
35 
36  void play(Ts... x) {
37  this->parent_->enqueue(make_unique<PowerCommand>(0));
38  if (this->factory_reset_.has_value() && this->factory_reset_.value(x...) == true) {
39  this->parent_->enqueue(make_unique<FactoryResetCommand>());
40  }
41  if (this->det_min1_.has_value() && this->det_max1_.has_value()) {
42  if (this->det_min1_.value() >= 0 && this->det_max1_.value() >= 0) {
43  this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
44  this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
45  this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
46  this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
47  }
48  }
49  if (this->delay_after_detect_.has_value() && this->delay_after_disappear_.has_value()) {
50  float detect = this->delay_after_detect_.value(x...);
51  float disappear = this->delay_after_disappear_.value(x...);
52  if (detect >= 0 && disappear >= 0) {
53  this->parent_->enqueue(make_unique<SetLatencyCommand>(detect, disappear));
54  }
55  }
56  if (this->start_after_power_on_.has_value()) {
57  int8_t val = this->start_after_power_on_.value(x...);
58  if (val >= 0) {
59  this->parent_->enqueue(make_unique<SensorCfgStartCommand>(val));
60  }
61  }
62  if (this->turn_on_led_.has_value()) {
63  int8_t val = this->turn_on_led_.value(x...);
64  if (val >= 0) {
65  this->parent_->enqueue(make_unique<LedModeCommand>(val));
66  }
67  }
68  if (this->presence_via_uart_.has_value()) {
69  int8_t val = this->presence_via_uart_.value(x...);
70  if (val >= 0) {
71  this->parent_->enqueue(make_unique<UartOutputCommand>(val));
72  }
73  }
74  if (this->sensitivity_.has_value()) {
75  int8_t val = this->sensitivity_.value(x...);
76  if (val >= 0) {
77  if (val > 9) {
78  val = 9;
79  }
80  this->parent_->enqueue(make_unique<SensitivityCommand>(val));
81  }
82  }
83  this->parent_->enqueue(make_unique<SaveCfgCommand>());
84  this->parent_->enqueue(make_unique<PowerCommand>(1));
85  }
86 };
87 
88 } // namespace dfrobot_sen0395
89 } // namespace esphome
uint16_t x
Definition: tt21100.cpp:17
mopeka_std_values val[4]
DfrobotSen0395Component * parent_
Definition: helpers.h:532
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Helper class to easily give an object a parent of type T.
Definition: helpers.h:521