|
@ -428,14 +428,34 @@ void _sensorRtcmemSaveEnergy(unsigned char index, const sensor::Energy& source) |
|
|
|
|
|
|
|
|
sensor::Energy _sensorParseEnergy(const String& value) { |
|
|
sensor::Energy _sensorParseEnergy(const String& value) { |
|
|
sensor::Energy result; |
|
|
sensor::Energy result; |
|
|
|
|
|
if (!value.length()) { |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const char* p { value.c_str() }; |
|
|
|
|
|
|
|
|
|
|
|
char* endp { nullptr }; |
|
|
|
|
|
auto kwh = strtoul(p, &endp, 10); |
|
|
|
|
|
if (!endp || (endp == p)) { |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
result.kwh = kwh; |
|
|
|
|
|
|
|
|
const bool separator = value.indexOf('+') > 0; |
|
|
|
|
|
if (value.length() && (separator > 0)) { |
|
|
|
|
|
const String before = value.substring(0, separator); |
|
|
|
|
|
const String after = value.substring(separator + 1); |
|
|
|
|
|
result.kwh = strtoul(before.c_str(), nullptr, 10); |
|
|
|
|
|
result.ws = strtoul(after.c_str(), nullptr, 10); |
|
|
|
|
|
|
|
|
const char* plus { strchr(p, '+') }; |
|
|
|
|
|
if (!plus) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
p = plus + 1; |
|
|
|
|
|
if (*p == '\0') { |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
auto ws = strtoul(p, &endp, 10); |
|
|
|
|
|
if (!endp || (endp == p)) { |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
result.ws = ws; |
|
|
|
|
|
|
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|