ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
statsd.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
6#if defined(USE_NETWORK) && !defined(USE_ZEPHYR)
10
11#ifdef USE_SENSOR
13#endif
14
15#ifdef USE_BINARY_SENSOR
17#endif
18
19#ifdef USE_LOGGER
21#endif
22
23namespace esphome::statsd {
24
25class StatsdComponent final : public PollingComponent {
26 public:
27 void setup() override;
28 void dump_config() override;
29 void update() override;
30 float get_setup_priority() const override;
31
32 void configure(const char *host, uint16_t port, const char *prefix) {
33 this->host_ = host;
34 this->port_ = port;
35 this->prefix_ = prefix;
36 }
37
38#ifdef USE_SENSOR
39 void register_sensor(const char *name, esphome::sensor::Sensor *sensor);
40#endif
41
42#ifdef USE_BINARY_SENSOR
43 void register_binary_sensor(const char *name, esphome::binary_sensor::BinarySensor *binary_sensor);
44#endif
45
46 private:
47 const char *host_;
48 const char *prefix_;
49 uint16_t port_;
50
51 using sensor_type_t = enum { TYPE_SENSOR, TYPE_BINARY_SENSOR };
52 using sensors_t = struct {
53 const char *name;
54 sensor_type_t type;
55 union {
56#ifdef USE_SENSOR
58#endif
59#ifdef USE_BINARY_SENSOR
61#endif
62 };
63 };
64
65 std::vector<sensors_t> sensors_;
66
67 std::unique_ptr<esphome::socket::UDPSendSocket> sock_;
68 struct sockaddr_in destination_{};
69
70 void send_(std::string *out);
71};
72
73} // namespace esphome::statsd
74
75#endif // USE_NETWORK && !USE_ZEPHYR
This class simplifies creating components that periodically check a state.
Definition component.h:519
Base class for all binary_sensor-type classes.
Base-class for all sensors.
Definition sensor.h:47
void configure(const char *host, uint16_t port, const char *prefix)
Definition statsd.h:32
void register_sensor(const char *name, esphome::sensor::Sensor *sensor)
Definition statsd.cpp:49
void register_binary_sensor(const char *name, esphome::binary_sensor::BinarySensor *binary_sensor)
Definition statsd.cpp:59
float get_setup_priority() const override
Definition statsd.cpp:46
uint8_t type
std::vector< uint8_t > & out
Definition gif.cpp:49