ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
statsd.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
6#ifdef USE_NETWORK
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 {
29namespace statsd {
30
32 public:
34
35 void setup() override;
36 void dump_config() override;
37 void update() override;
38 float get_setup_priority() const override;
39
40 void configure(const char *host, uint16_t port, const char *prefix) {
41 this->host_ = host;
42 this->port_ = port;
43 this->prefix_ = prefix;
44 }
45
46#ifdef USE_SENSOR
47 void register_sensor(const char *name, esphome::sensor::Sensor *sensor);
48#endif
49
50#ifdef USE_BINARY_SENSOR
51 void register_binary_sensor(const char *name, esphome::binary_sensor::BinarySensor *binary_sensor);
52#endif
53
54 private:
55 const char *host_;
56 const char *prefix_;
57 uint16_t port_;
58
59 using sensor_type_t = enum { TYPE_SENSOR, TYPE_BINARY_SENSOR };
60 using sensors_t = struct {
61 const char *name;
62 sensor_type_t type;
63 union {
64#ifdef USE_SENSOR
66#endif
67#ifdef USE_BINARY_SENSOR
69#endif
70 };
71 };
72
73 std::vector<sensors_t> sensors_;
74
75#ifdef USE_ESP8266
76 WiFiUDP sock_;
77#else
78 std::unique_ptr<esphome::socket::Socket> sock_;
79 struct sockaddr_in destination_;
80#endif
81
82 void send_(std::string *out);
83};
84
85} // namespace statsd
86} // namespace esphome
87#endif
This class simplifies creating components that periodically check a state.
Definition component.h:437
Base class for all binary_sensor-type classes.
Base-class for all sensors.
Definition sensor.h:42
void configure(const char *host, uint16_t port, const char *prefix)
Definition statsd.h:40
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
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7