ESPHome 2026.6.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
23#ifdef USE_ESP8266
24#include "WiFiUdp.h"
25#include "IPAddress.h"
26#endif
27
28namespace esphome::statsd {
29
31 public:
33
34 void setup() override;
35 void dump_config() override;
36 void update() override;
37 float get_setup_priority() const override;
38
39 void configure(const char *host, uint16_t port, const char *prefix) {
40 this->host_ = host;
41 this->port_ = port;
42 this->prefix_ = prefix;
43 }
44
45#ifdef USE_SENSOR
46 void register_sensor(const char *name, esphome::sensor::Sensor *sensor);
47#endif
48
49#ifdef USE_BINARY_SENSOR
50 void register_binary_sensor(const char *name, esphome::binary_sensor::BinarySensor *binary_sensor);
51#endif
52
53 private:
54 const char *host_;
55 const char *prefix_;
56 uint16_t port_;
57
58 using sensor_type_t = enum { TYPE_SENSOR, TYPE_BINARY_SENSOR };
59 using sensors_t = struct {
60 const char *name;
61 sensor_type_t type;
62 union {
63#ifdef USE_SENSOR
65#endif
66#ifdef USE_BINARY_SENSOR
68#endif
69 };
70 };
71
72 std::vector<sensors_t> sensors_;
73
74#ifdef USE_ESP8266
75 WiFiUDP sock_;
76#else
77 std::unique_ptr<esphome::socket::Socket> sock_;
78 struct sockaddr_in destination_;
79#endif
80
81 void send_(std::string *out);
82};
83
84} // namespace esphome::statsd
85
86#endif // USE_NETWORK && !USE_ZEPHYR
This class simplifies creating components that periodically check a state.
Definition component.h:585
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:39
void register_sensor(const char *name, esphome::sensor::Sensor *sensor)
Definition statsd.cpp:62
void register_binary_sensor(const char *name, esphome::binary_sensor::BinarySensor *binary_sensor)
Definition statsd.cpp:72
float get_setup_priority() const override
Definition statsd.cpp:59
uint16_t type