mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
Fix ezo parsing (#4792)
This commit is contained in:
parent
ffdc721c79
commit
b5dac00dcb
1 changed files with 11 additions and 10 deletions
|
@ -106,20 +106,18 @@ void EZOSensor::loop() {
|
|||
break;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Received buffer \"%s\" for command type %s", buf, EZO_COMMAND_TYPE_STRINGS[to_run->command_type]);
|
||||
ESP_LOGV(TAG, "Received buffer \"%s\" for command type %s", &buf[1], EZO_COMMAND_TYPE_STRINGS[to_run->command_type]);
|
||||
|
||||
if ((buf[0] == 1) || (to_run->command_type == EzoCommandType::EZO_CALIBRATION)) { // EZO_CALIBRATION returns 0-3
|
||||
// some sensors return multiple comma-separated values, terminate string after first one
|
||||
for (size_t i = 1; i < sizeof(buf) - 1; i++) {
|
||||
if (buf[i] == ',') {
|
||||
buf[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (buf[0] == 1) {
|
||||
std::string payload = reinterpret_cast<char *>(&buf[1]);
|
||||
if (!payload.empty()) {
|
||||
switch (to_run->command_type) {
|
||||
case EzoCommandType::EZO_READ: {
|
||||
// some sensors return multiple comma-separated values, terminate string after first one
|
||||
int start_location = 0;
|
||||
if ((start_location = payload.find(',')) != std::string::npos) {
|
||||
payload.erase(start_location);
|
||||
}
|
||||
auto val = parse_number<float>(payload);
|
||||
if (!val.has_value()) {
|
||||
ESP_LOGW(TAG, "Can't convert '%s' to number!", payload.c_str());
|
||||
|
@ -154,7 +152,10 @@ void EZOSensor::loop() {
|
|||
break;
|
||||
}
|
||||
case EzoCommandType::EZO_T: {
|
||||
this->t_callback_.call(payload);
|
||||
int start_location = 0;
|
||||
if ((start_location = payload.find(',')) != std::string::npos) {
|
||||
this->t_callback_.call(payload.substr(start_location + 1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EzoCommandType::EZO_CUSTOM: {
|
||||
|
|
Loading…
Reference in a new issue