Skip to content

Commit

Permalink
Fix tbnobody#540: Do not output unit_of_meas if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Jan 27, 2023
1 parent d867c0e commit 8bafb17
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MqttHandleHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ void MqttHandleHassClass::publishField(std::shared_ptr<InverterAbstract> inv, ui
DynamicJsonDocument root(1024);
root[F("name")] = name;
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;

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");
createDeviceInfo(deviceObj, inv);

Expand Down

0 comments on commit 8bafb17

Please sign in to comment.