ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
teleinfo_sensor.cpp
Go to the documentation of this file.
1#include "esphome/core/log.h"
2#include "teleinfo_sensor.h"
3
5
6ESPHOME_LOG_TAG(TAG, "teleinfo_sensor");
7TeleInfoSensor::TeleInfoSensor(const char *tag) { this->tag = std::string(tag); }
8void TeleInfoSensor::publish_val(const std::string &val) {
9 auto newval = parse_number<float>(val);
10 if (!newval.has_value()) {
11 // Publishing 0 instead would look like a meter reset to total_increasing energy sensors
12 ESP_LOGW(TAG, "Value '%s' for tag %s is not a number", val.c_str(), this->tag.c_str());
13 return;
14 }
15 this->publish_state(*newval);
16}
17void TeleInfoSensor::dump_config() { LOG_SENSOR(" ", "Teleinfo Sensor", this); }
18} // namespace esphome::teleinfo
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
void publish_val(const std::string &val) override
mopeka_std_values val[3]
ESPHOME_LOG_TAG(TAG, "teleinfo_sensor")
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
Definition helpers.h:1352