Teleinfo ptec (#2599)

* teleinfo: handle historical mode correctly.

In historical mode, tags like PTEC leads to an issue where we detect a
timestamp wheras this is not possible in historical mode.

PTEC teleinfo tag looks like:
    PTEC HP..
Instead of the usual format
    IINST1 001 I

This make our data parsing fails.

While at here, make sure we continue parsing other tags even if parsing
one of the tag fails.

Signed-off-by: 0hax <0hax@protonmail.com>

* teleinfo: fix compilation with loglevel set to debug.

Signed-off-by: 0hax <0hax@protonmail.com>
This commit is contained in:
0hax 2021-10-23 19:01:23 +02:00 committed by GitHub
parent b9e5c7eb35
commit a687b083ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View File

@ -9,6 +9,6 @@ void TeleInfoSensor::publish_val(const std::string &val) {
auto newval = parse_float(val); auto newval = parse_float(val);
publish_state(*newval); publish_state(*newval);
} }
void TeleInfoSensor::dump_config() { LOG_SENSOR(" ", tag.c_str(), this); } void TeleInfoSensor::dump_config() { LOG_SENSOR(" ", "Teleinfo Sensor", this); }
} // namespace teleinfo } // namespace teleinfo
} // namespace esphome } // namespace esphome

View File

@ -141,21 +141,22 @@ void TeleInfo::loop() {
field_len = get_field(tag_, buf_finger, grp_end, separator_, MAX_TAG_SIZE); field_len = get_field(tag_, buf_finger, grp_end, separator_, MAX_TAG_SIZE);
if (!field_len || field_len >= MAX_TAG_SIZE) { if (!field_len || field_len >= MAX_TAG_SIZE) {
ESP_LOGE(TAG, "Invalid tag."); ESP_LOGE(TAG, "Invalid tag.");
break; continue;
} }
/* Advance buf_finger to after the tag and the separator. */ /* Advance buf_finger to after the tag and the separator. */
buf_finger += field_len + 1; buf_finger += field_len + 1;
/* /*
* If there is two separators and the tag is not equal to "DATE", * If there is two separators and the tag is not equal to "DATE" or
* it means there is a timestamp to read first. * historical mode is not in use (separator_ != 0x20), it means there is a
* timestamp to read first.
*/ */
if (std::count(buf_finger, grp_end, separator_) == 2 && strcmp(tag_, "DATE") != 0) { if (std::count(buf_finger, grp_end, separator_) == 2 && strcmp(tag_, "DATE") != 0 && separator_ != 0x20) {
field_len = get_field(timestamp_, buf_finger, grp_end, separator_, MAX_TIMESTAMP_SIZE); field_len = get_field(timestamp_, buf_finger, grp_end, separator_, MAX_TIMESTAMP_SIZE);
if (!field_len || field_len >= MAX_TIMESTAMP_SIZE) { if (!field_len || field_len >= MAX_TIMESTAMP_SIZE) {
ESP_LOGE(TAG, "Invalid Timestamp"); ESP_LOGE(TAG, "Invalid timestamp for tag %s", timestamp_);
break; continue;
} }
/* Advance buf_finger to after the first data and the separator. */ /* Advance buf_finger to after the first data and the separator. */
@ -164,8 +165,8 @@ void TeleInfo::loop() {
field_len = get_field(val_, buf_finger, grp_end, separator_, MAX_VAL_SIZE); field_len = get_field(val_, buf_finger, grp_end, separator_, MAX_VAL_SIZE);
if (!field_len || field_len >= MAX_VAL_SIZE) { if (!field_len || field_len >= MAX_VAL_SIZE) {
ESP_LOGE(TAG, "Invalid Value"); ESP_LOGE(TAG, "Invalid value for tag %s", tag_);
break; continue;
} }
/* Advance buf_finger to end of group */ /* Advance buf_finger to end of group */

View File

@ -6,6 +6,6 @@ namespace teleinfo {
static const char *const TAG = "teleinfo_text_sensor"; static const char *const TAG = "teleinfo_text_sensor";
TeleInfoTextSensor::TeleInfoTextSensor(const char *tag) { this->tag = std::string(tag); } TeleInfoTextSensor::TeleInfoTextSensor(const char *tag) { this->tag = std::string(tag); }
void TeleInfoTextSensor::publish_val(const std::string &val) { publish_state(val); } void TeleInfoTextSensor::publish_val(const std::string &val) { publish_state(val); }
void TeleInfoTextSensor::dump_config() { LOG_TEXT_SENSOR(" ", tag.c_str(), this); } void TeleInfoTextSensor::dump_config() { LOG_TEXT_SENSOR(" ", "Teleinfo Text Sensor", this); }
} // namespace teleinfo } // namespace teleinfo
} // namespace esphome } // namespace esphome