ESPHome 2026.11.0b6
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 PUBLISH_STATE(sensor, sample != nullptr ? sample->*field * scale : NAN);
15}
16
18 using Sample = ::espectre::RuntimeDiagnosticsSample;
19 const auto *sample = this->parent_->diagnostics_sample();
20 publish_diagnostic(this->generator_rate_sensor_, sample, &Sample::generator_pps);
21 publish_diagnostic(this->traffic_tx_rate_sensor_, sample, &Sample::traffic_tx_pps);
22 publish_diagnostic(this->traffic_rx_rate_sensor_, sample, &Sample::traffic_rx_pps);
23 publish_diagnostic(this->csi_callback_rate_sensor_, sample, &Sample::csi_callback_pps);
24 publish_diagnostic(this->csi_accepted_rate_sensor_, sample, &Sample::csi_accepted_pps);
25 publish_diagnostic(this->csi_missing_slot_rate_sensor_, sample, &Sample::csi_missing_slots_pps);
26 publish_diagnostic(this->csi_excess_rate_sensor_, sample, &Sample::csi_excess_pps);
27 publish_diagnostic(this->csi_occupancy_sensor_, sample, &Sample::csi_occupancy_ratio, 100.0f);
28}
29
31 ESP_LOGCONFIG(TAG, "ESPectre diagnostics:");
32 LOG_UPDATE_INTERVAL(this);
33 LOG_SENSOR(" ", "Generator rate", this->generator_rate_sensor_);
34 LOG_SENSOR(" ", "Traffic TX rate", this->traffic_tx_rate_sensor_);
35 LOG_SENSOR(" ", "Traffic RX rate", this->traffic_rx_rate_sensor_);
36 LOG_SENSOR(" ", "CSI callback rate", this->csi_callback_rate_sensor_);
37 LOG_SENSOR(" ", "CSI accepted rate", this->csi_accepted_rate_sensor_);
38 LOG_SENSOR(" ", "CSI missing slot rate", this->csi_missing_slot_rate_sensor_);
39 LOG_SENSOR(" ", "CSI excess rate", this->csi_excess_rate_sensor_);
40 LOG_SENSOR(" ", "CSI occupancy", this->csi_occupancy_sensor_);
41}
42
43} // namespace esphome::espectre
44
45#endif // USE_ESPECTRE
Base-class for all sensors.
Definition sensor.h:48
ESPHOME_LOG_TAG(TAG, "espectre")