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