ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
espectre.h
Go to the documentation of this file.
1#pragma once
2
4
5#ifdef USE_ESPECTRE
6
10#include <espectre_sdk.h>
11#include <string>
12#ifdef USE_BINARY_SENSOR
14#endif
15#ifdef USE_SELECT
18#endif
19#ifdef USE_SENSOR
21#endif
22
23namespace esphome::espectre {
24
25class ESPectreComponent final : public Component, public ::espectre::IRuntimeListener {
26 public:
27 void setup() override;
28 void loop() override;
29 void dump_config() override;
30 void on_shutdown() override;
31 // Register the SDK's Wi-Fi event handlers after network setup, before station startup.
32 float get_setup_priority() const override { return setup_priority::WIFI + 1.0f; }
33
34 void set_detection_algorithm(::espectre::DetectionAlgorithm value) {
35 this->runtime_.config().detection_algorithm = value;
36 }
37 void set_csi_capture_profile(::espectre::CsiCapturePolicy value) {
38 this->runtime_.config().csi_capture_policy = value;
39 }
40 void set_traffic_generator_mode(::espectre::TrafficGeneratorMode value) {
41 this->runtime_.config().traffic_generator_mode = value;
42 }
43 void set_traffic_generator_target_ip(const std::string &value) {
44 this->runtime_.config().traffic_generator_target_ip = value;
45 }
46 void set_csi_traffic_multicast_group(const std::string &value) {
47 this->runtime_.config().csi_traffic_multicast_group = value;
48 }
49 void set_motion_on_hits(uint8_t value) { this->runtime_.config().motion_on_hits = value; }
50 void set_motion_off_hits(uint8_t value) { this->runtime_.config().motion_off_hits = value; }
51 void set_wifi_band_policy(::espectre::WifiBandPolicy value) { this->runtime_.config().wifi_band_policy = value; }
52 // Queue controls so entity automations cannot re-enter the SDK from a listener callback.
53 void recalibrate() { this->recalibrate_pending_ = true; }
54#ifdef USE_SELECT
56 void request_traffic_generator_mode(::espectre::TrafficGeneratorMode mode) { this->pending_traffic_mode_ = mode; }
58 void request_traffic_generator_mode(const char *name);
59#endif
60
61#ifdef USE_BINARY_SENSOR
62 SUB_BINARY_SENSOR(motion)
63 SUB_BINARY_SENSOR(calibrating)
64#endif
65#ifdef USE_SENSOR
66 SUB_SENSOR(movement)
67#endif
69 const ::espectre::RuntimeDiagnosticsSample *diagnostics_sample() const { return this->runtime_.diagnostics_sample(); }
70
71 protected:
72 // Called once per SDK detector evaluation (every 250 ms), which bounds the movement publish rate.
73 void on_live_telemetry(const ::espectre::RuntimeSnapshot &snapshot) override { this->movement_pending_ = true; }
74 void on_calibration_finished(const ::espectre::RuntimeSnapshot &snapshot, bool success) override;
75 void on_runtime_fault(const char *message) override;
76 void start_runtime_();
77 void schedule_restart_();
79 void stop_();
80#ifdef USE_SELECT
84#endif
85
86 static constexpr uint32_t RESTART_DELAY_MS = 30000;
87
88 ::espectre::RuntimeFrontendController runtime_;
90#ifdef USE_SELECT
93 optional<::espectre::TrafficGeneratorMode> pending_traffic_mode_;
94#endif
96 bool movement_pending_{false};
97 bool ready_{false};
98 bool motion_state_{false};
99 bool calibrating_state_{false};
101 bool runtime_fault_{false};
102 bool running_{false};
103 bool restart_pending_{false};
104 bool calibrated_{false};
106};
107
108} // namespace esphome::espectre
109
110#endif // USE_ESPECTRE
BedjetMode mode
BedJet operating mode.
void set_csi_capture_profile(::espectre::CsiCapturePolicy value)
Definition espectre.h:37
void set_motion_on_hits(uint8_t value)
Definition espectre.h:49
void set_traffic_mode_select(select::Select *value)
Definition espectre.h:55
SUB_BINARY_SENSOR(motion) SUB_BINARY_SENSOR(calibrating) SUB_SENSOR(movement) const void on_runtime_fault(const char *message) override
Latest one-second runtime diagnostics sample, or nullptr before the runtime starts.
Definition espectre.cpp:248
void request_traffic_generator_mode(::espectre::TrafficGeneratorMode mode)
Definition espectre.h:56
optional<::espectre::TrafficGeneratorMode > pending_traffic_mode_
Definition espectre.h:93
void set_traffic_generator_target_ip(const std::string &value)
Definition espectre.h:43
void set_wifi_band_policy(::espectre::WifiBandPolicy value)
Definition espectre.h:51
ESPPreferenceObject traffic_mode_pref_
Definition espectre.h:92
void set_csi_traffic_multicast_group(const std::string &value)
Definition espectre.h:46
float get_setup_priority() const override
Definition espectre.h:32
void set_traffic_generator_mode(::espectre::TrafficGeneratorMode value)
Definition espectre.h:40
void set_detection_algorithm(::espectre::DetectionAlgorithm value)
Definition espectre.h:34
void set_motion_off_hits(uint8_t value)
Definition espectre.h:50
static constexpr uint32_t RESTART_DELAY_MS
Definition espectre.h:86
::espectre::RuntimeFrontendController runtime_
Definition espectre.h:88
select::Select * traffic_mode_select_
Definition espectre.h:91
Base-class for all selects.
Definition select.h:29
const LogString * message
Definition component.cpp:35
constexpr float WIFI
Definition component.h:50
static void uint32_t