ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
espectre_diagnostics.cpp
Go to the documentation of this file.
2
3#ifdef USE_ESPECTRE
4
5#include <cmath>
6#include "esphome/core/log.h"
7
8namespace esphome::espectre {
9
10ESPHOME_LOG_TAG(TAG, "espectre.sensor");
11
12static void publish_diagnostic(sensor::Sensor *sensor, const ::espectre::RuntimeDiagnosticsSample *sample,
13 float ::espectre::RuntimeDiagnosticsSample::*field, float scale = 1.0f) {
14 if (sensor != nullptr)
15 sensor->publish_state(sample != nullptr ? sample->*field * scale : NAN);
16}
17
19 using Sample = ::espectre::RuntimeDiagnosticsSample;
20 const auto *sample = this->parent_->diagnostics_sample();
21 publish_diagnostic(this->generator_rate_sensor_, sample, &Sample::generator_pps);
22 publish_diagnostic(this->traffic_tx_rate_sensor_, sample, &Sample::traffic_tx_pps);
23 publish_diagnostic(this->traffic_rx_rate_sensor_, sample, &Sample::traffic_rx_pps);
24 publish_diagnostic(this->csi_accepted_rate_sensor_, sample, &Sample::csi_accepted_pps);
25 publish_diagnostic(this->csi_occupancy_sensor_, sample, &Sample::csi_occupancy_ratio, 100.0f);
26}
27
29 ESP_LOGCONFIG(TAG, "ESPectre diagnostics:");
30 LOG_UPDATE_INTERVAL(this);
31 LOG_SENSOR(" ", "Generator rate", this->generator_rate_sensor_);
32 LOG_SENSOR(" ", "Traffic TX rate", this->traffic_tx_rate_sensor_);
33 LOG_SENSOR(" ", "Traffic RX rate", this->traffic_rx_rate_sensor_);
34 LOG_SENSOR(" ", "CSI accepted rate", this->csi_accepted_rate_sensor_);
35 LOG_SENSOR(" ", "CSI occupancy", this->csi_occupancy_sensor_);
36}
37
38} // namespace esphome::espectre
39
40#endif // USE_ESPECTRE
Base-class for all sensors.
Definition sensor.h:47
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
ESPHOME_LOG_TAG(TAG, "espectre")