teleinfo: use text_sensor and sensor. (#1403)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Otto winter <otto@otto-winter.com>
This commit is contained in:
0hax
2021-06-01 03:32:09 +02:00
committed by GitHub
parent 48b5ea9e59
commit afa436fe8f
11 changed files with 163 additions and 87 deletions
+6 -7
View File
@@ -1,7 +1,6 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/uart/uart.h"
namespace esphome {
@@ -14,20 +13,20 @@ static const uint8_t MAX_TAG_SIZE = 64;
static const uint16_t MAX_VAL_SIZE = 256;
static const uint16_t MAX_BUF_SIZE = 1024;
struct TeleinfoSensorElement {
const char *tag;
sensor::Sensor *sensor;
class TeleInfoListener {
public:
std::string tag;
virtual void publish_val(std::string val){};
};
class TeleInfo : public PollingComponent, public uart::UARTDevice {
public:
TeleInfo(bool historical_mode);
void register_teleinfo_sensor(const char *tag, sensor::Sensor *sensors);
void register_teleinfo_listener(TeleInfoListener *listener);
void loop() override;
void setup() override;
void update() override;
void dump_config() override;
std::vector<const TeleinfoSensorElement *> teleinfo_sensors_{};
std::vector<TeleInfoListener *> teleinfo_listeners_{};
protected:
uint32_t baud_rate_;