ESPHome  2024.9.2
statsd.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
5 #include "esphome/core/defines.h"
9 
10 #ifdef USE_SENSOR
12 #endif
13 
14 #ifdef USE_BINARY_SENSOR
16 #endif
17 
18 #ifdef USE_LOGGER
20 #endif
21 
22 #ifdef USE_ESP8266
23 #include "WiFiUdp.h"
24 #include "IPAddress.h"
25 #endif
26 
27 namespace esphome {
28 namespace statsd {
29 
30 using sensor_type_t = enum { TYPE_SENSOR, TYPE_BINARY_SENSOR };
31 
32 using sensors_t = struct {
33  const char *name;
35  union {
36 #ifdef USE_SENSOR
38 #endif
39 #ifdef USE_BINARY_SENSOR
41 #endif
42  };
43 };
44 
46  public:
48 
49  void setup() override;
50  void dump_config() override;
51  void update() override;
52  float get_setup_priority() const override;
53 
54  void configure(const char *host, uint16_t port, const char *prefix) {
55  this->host_ = host;
56  this->port_ = port;
57  this->prefix_ = prefix;
58  }
59 
60 #ifdef USE_SENSOR
62 #endif
63 
64 #ifdef USE_BINARY_SENSOR
66 #endif
67 
68  private:
69  const char *host_;
70  const char *prefix_;
71  uint16_t port_;
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
const char * name
Definition: stm32flash.h:78
void configure(const char *host, uint16_t port, const char *prefix)
Definition: statsd.h:54
void dump_config() override
Definition: statsd.cpp:39
struct { const char *name sensors_t
Definition: statsd.h:33
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:30
sensor_type_t type
Definition: statsd.h:34
void register_binary_sensor(const char *name, esphome::binary_sensor::BinarySensor *binary_sensor)
Definition: statsd.cpp:67
float get_setup_priority() const override
Definition: statsd.cpp:54
esphome::binary_sensor::BinarySensor * binary_sensor
Definition: statsd.h:40
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:57
Base-class for all sensors.
Definition: sensor.h:57
esphome::sensor::Sensor * sensor
Definition: statsd.h:37