mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
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:
parent
b9e5c7eb35
commit
a687b083ae
3 changed files with 11 additions and 10 deletions
|
@ -9,6 +9,6 @@ void TeleInfoSensor::publish_val(const std::string &val) {
|
|||
auto newval = parse_float(val);
|
||||
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 esphome
|
||||
|
|
|
@ -141,21 +141,22 @@ void TeleInfo::loop() {
|
|||
field_len = get_field(tag_, buf_finger, grp_end, separator_, MAX_TAG_SIZE);
|
||||
if (!field_len || field_len >= MAX_TAG_SIZE) {
|
||||
ESP_LOGE(TAG, "Invalid tag.");
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Advance buf_finger to after the tag and the separator. */
|
||||
buf_finger += field_len + 1;
|
||||
|
||||
/*
|
||||
* If there is two separators and the tag is not equal to "DATE",
|
||||
* it means there is a timestamp to read first.
|
||||
* If there is two separators and the tag is not equal to "DATE" or
|
||||
* 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);
|
||||
if (!field_len || field_len >= MAX_TIMESTAMP_SIZE) {
|
||||
ESP_LOGE(TAG, "Invalid Timestamp");
|
||||
break;
|
||||
ESP_LOGE(TAG, "Invalid timestamp for tag %s", timestamp_);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
if (!field_len || field_len >= MAX_VAL_SIZE) {
|
||||
ESP_LOGE(TAG, "Invalid Value");
|
||||
break;
|
||||
ESP_LOGE(TAG, "Invalid value for tag %s", tag_);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Advance buf_finger to end of group */
|
||||
|
|
|
@ -6,6 +6,6 @@ namespace teleinfo {
|
|||
static const char *const TAG = "teleinfo_text_sensor";
|
||||
TeleInfoTextSensor::TeleInfoTextSensor(const char *tag) { this->tag = std::string(tag); }
|
||||
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 esphome
|
||||
|
|
Loading…
Reference in a new issue