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 -11
View File
@@ -149,16 +149,14 @@ void TeleInfo::loop() {
}
}
void TeleInfo::publish_value_(std::string tag, std::string val) {
/* It will return 0 if tag is not a float. */
auto newval = parse_float(val);
for (auto element : teleinfo_sensors_)
if (tag == element->tag)
element->sensor->publish_state(*newval);
for (auto element : teleinfo_listeners_) {
if (tag != element->tag)
continue;
element->publish_val(val);
}
}
void TeleInfo::dump_config() {
ESP_LOGCONFIG(TAG, "TeleInfo:");
for (auto element : teleinfo_sensors_)
LOG_SENSOR(" ", element->tag, element->sensor);
this->check_uart_settings(baud_rate_, 1, uart::UART_CONFIG_PARITY_EVEN, 7);
}
TeleInfo::TeleInfo(bool historical_mode) {
@@ -175,10 +173,7 @@ TeleInfo::TeleInfo(bool historical_mode) {
baud_rate_ = 9600;
}
}
void TeleInfo::register_teleinfo_sensor(const char *tag, sensor::Sensor *sensor) {
const TeleinfoSensorElement *teleinfo_sensor = new TeleinfoSensorElement{tag, sensor};
teleinfo_sensors_.push_back(teleinfo_sensor);
}
void TeleInfo::register_teleinfo_listener(TeleInfoListener *listener) { teleinfo_listeners_.push_back(listener); }
} // namespace teleinfo
} // namespace esphome