-
Notifications
You must be signed in to change notification settings - Fork 21
/
influxdb_writer.h
62 lines (51 loc) · 1.77 KB
/
influxdb_writer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once
#include <vector>
#include <WiFiUdp.h>
#include "esphome/core/component.h"
#include "esphome/core/controller.h"
#include "esphome/core/defines.h"
#include "esphome/core/log.h"
namespace esphome {
namespace influxdb {
// struct SensorConfig {
// bool ignore;
// std::string measurement;
// std:vector<std::pair<std::string, std::string>> tags;
// }
class InfluxDBWriter : public Component {
public:
InfluxDBWriter() : packet_size(0) { };
void setup() override;
void loop() override;
void dump_config() override;
#ifdef USE_BINARY_SENSOR
void on_sensor_update(binary_sensor::BinarySensor *obj, std::string measurement, std::string tags, bool state);
#endif
#ifdef USE_SENSOR
void on_sensor_update(sensor::Sensor *obj, std::string measurement, std::string tags, float state);
#endif
#ifdef USE_TEXT_SENSOR
void on_sensor_update(text_sensor::TextSensor *obj, std::string measurement, std::string tags, std::string state);
#endif
void set_host(std::string host) { this->host = host; };
void set_port(uint16_t port) { this->port = port; };
void set_send_timeout(int timeout) { send_timeout = timeout; };
void set_max_packet_size(int size) { max_packet_size = size; };
void set_tags(std::string tags) { this->tags = tags; };
void set_publish_all(bool all) { publish_all = all; };
void add_setup_callback(std::function<Nameable*()> fun) { setup_callbacks.push_back(fun); };
protected:
void write(std::string measurement, std::string tags, const std::string value, bool is_string);
uint16_t port;
std::string host;
int max_packet_size;
int send_timeout;
std::string tags;
bool publish_all;
std::vector<std::function<Nameable*()>> setup_callbacks;
WiFiUDP udp;
int packet_size;
int packet_timeout;
};
} // namespace api
} // namespace esphome