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