add support for receving only voltage

This commit is contained in:
Nicu Hodos 2023-02-22 21:59:14 +01:00
parent 4cee82f28d
commit 1568eec6ee

View File

@ -5,10 +5,12 @@ bool buildSensorJson(unsigned long value, JsonDocument& jsonDoc) {
JsonObject sensor = jsonDoc.createNestedObject("sensor");
sensor["id"] = ID(value);
bool hasVoltage = false;
float voltage = (float)GET_VCC(value) / 1000;
if (voltage != 0) {
JsonObject diagnostic = sensor.createNestedObject("diagnostic");
diagnostic["voltage"] = voltage;
hasVoltage = true;
}
switch (GET_TYPE(value)) {
@ -25,7 +27,7 @@ bool buildSensorJson(unsigned long value, JsonDocument& jsonDoc) {
sensor["state"] = GET_STATE(value) ? "on" : "off";
break;
default:
return false;
return hasVoltage;
}
return true;