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