ESPHome  2024.11.1
statsd.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
5 #include "esphome/core/defines.h"
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 
28 namespace esphome {
29 namespace statsd {
30 
31 using sensor_type_t = enum { TYPE_SENSOR, TYPE_BINARY_SENSOR };
32 
33 using 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
63 #endif
64 
65 #ifdef USE_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
const char * name
Definition: stm32flash.h:78
void configure(const char *host, uint16_t port, const char *prefix)
Definition: statsd.h:55
void dump_config() override
Definition: statsd.cpp:40
struct { const char *name sensors_t
Definition: statsd.h:34
This class simplifies creating components that periodically check a state.
Definition: component.h:283
enum { TYPE_SENSOR, TYPE_BINARY_SENSOR } sensor_type_t
Definition: statsd.h:31
sensor_type_t type
Definition: statsd.h:35
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
esphome::binary_sensor::BinarySensor * binary_sensor
Definition: statsd.h:41
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
void register_sensor(const char *name, esphome::sensor::Sensor *sensor)
Definition: statsd.cpp:58
Base-class for all sensors.
Definition: sensor.h:57
esphome::sensor::Sensor * sensor
Definition: statsd.h:38