Fix parsing of multiple values in EZO sensor (#2814)

Co-authored-by: Lydia Sevelt <LydiaSevelt@gmail.com>
This commit is contained in:
Oxan van Leeuwen 2021-11-28 20:02:10 +01:00 committed by Jesse Hills
parent db2128a344
commit 3d5e1d8d91
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

View File

@ -74,6 +74,11 @@ void EZOSensor::loop() {
if (buf[0] != 1) if (buf[0] != 1)
return; return;
// some sensors return multiple comma-separated values, terminate string after first one
for (int i = 1; i < sizeof(buf) - 1; i++)
if (buf[i] == ',')
buf[i] = '\0';
float val = parse_number<float>((char *) &buf[1], sizeof(buf) - 2).value_or(0); float val = parse_number<float>((char *) &buf[1], sizeof(buf) - 2).value_or(0);
this->publish_state(val); this->publish_state(val);
} }