ESPHome 2026.8.0b4
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1// Scan-control actions for ln882h_ble_tracker. The automation triggers are the
2// neutral ble_device_base classes (ble_device_base/automation.h).
3
4#pragma once
5
6#ifdef USE_LIBRETINY
7
9
12
14
15template<typename... Ts> class StartScanAction final : public Action<Ts...>, public Parented<LN882HBLETracker> {
16 public:
17 TEMPLATABLE_VALUE(bool, continuous)
18 void play(const Ts &...x) override {
19 // With continuous: set, the action wins. Without it, the configured value
20 // is used - stop_scan() clears the runtime flag permanently, so a bare
21 // stop_scan/start_scan pair would otherwise never resume continuous mode.
22 const bool want =
23 this->continuous_.has_value() ? this->continuous_.value(x...) : this->parent_->configured_continuous();
24 if (this->parent_->scan_running()) {
25 // Same mode on a running scan is a no-op (esp32 parity): re-anchoring
26 // the duration window here would let a repeated action keep a one-shot
27 // scan alive forever. A real mode switch re-anchors so a change to
28 // one-shot runs a full duration from now.
29 if (want != this->parent_->scan_continuous()) {
30 this->parent_->set_scan_continuous(want);
31 this->parent_->restart_scan_duration();
32 }
33 return;
34 }
35 this->parent_->set_scan_continuous(want);
36 this->parent_->start_scan();
37 }
38};
39
40template<typename... Ts> class StopScanAction final : public Action<Ts...>, public Parented<LN882HBLETracker> {
41 public:
42 void play(const Ts &...x) override { this->parent_->stop_scan(); }
43};
44
45} // namespace esphome::ln882h_ble_tracker
46
47#endif // USE_LIBRETINY
virtual void play(const Ts &...x)=0
Helper class to easily give an object a parent of type T.
Definition helpers.h:1907
TEMPLATABLE_VALUE(bool, continuous) void play(const Ts &...x) override
Definition automation.h:17
void play(const Ts &...x) override
Definition automation.h:42
uint16_t x
Definition tt21100.cpp:5