Fix #540: Do not output unit_of_meas if empty
This commit is contained in:
parent
d867c0e78d
commit
8bafb178a1
@ -113,9 +113,13 @@ void MqttHandleHassClass::publishField(std::shared_ptr<InverterAbstract> inv, ui
|
|||||||
DynamicJsonDocument root(1024);
|
DynamicJsonDocument root(1024);
|
||||||
root[F("name")] = name;
|
root[F("name")] = name;
|
||||||
root[F("stat_t")] = stateTopic;
|
root[F("stat_t")] = stateTopic;
|
||||||
root[F("unit_of_meas")] = inv->Statistics()->getChannelFieldUnit(channel, fieldType.fieldId);
|
|
||||||
root[F("uniq_id")] = serial + "_ch" + String(channel) + "_" + fieldName;
|
root[F("uniq_id")] = serial + "_ch" + String(channel) + "_" + fieldName;
|
||||||
|
|
||||||
|
String unit_of_meausure = inv->Statistics()->getChannelFieldUnit(channel, fieldType.fieldId);
|
||||||
|
if (unit_of_meausure != "") {
|
||||||
|
root[F("unit_of_meas")] = unit_of_meausure;
|
||||||
|
}
|
||||||
|
|
||||||
JsonObject deviceObj = root.createNestedObject("dev");
|
JsonObject deviceObj = root.createNestedObject("dev");
|
||||||
createDeviceInfo(deviceObj, inv);
|
createDeviceInfo(deviceObj, inv);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user