[mqtt.homie] populate unit hint on dynamic channels (#17649)

Signed-off-by: Cody Cutrer <cody@cutrer.us>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Cody Cutrer 2024-10-28 12:20:01 -06:00 committed by Ciprian Pascu
parent 29cca2cdac
commit 993a21c3b1

View File

@ -267,7 +267,8 @@ public class Property implements AttributeChanged {
if (attributes.datatype.equals(DataTypeEnum.unknown)) {
channelTypeId = MqttBindingConstants.CHANNEL_TYPE_HOMIE_STRING;
} else if (dimension != null) {
channelTypeId = MqttBindingConstants.CHANNEL_TYPE_HOMIE_PREFIX + "number-" + dimension.toLowerCase();
channelTypeId = MqttBindingConstants.CHANNEL_TYPE_HOMIE_PREFIX + "number-"
+ UIDUtils.encode(unit.toString().toLowerCase());
channelProperties.put(MqttBindingConstants.CHANNEL_PROPERTY_DATATYPE, attributes.datatype.toString());
} else {
channelTypeId = MqttBindingConstants.CHANNEL_TYPE_HOMIE_PREFIX + attributes.datatype.toString();
@ -275,8 +276,9 @@ public class Property implements AttributeChanged {
}
this.channelTypeUID = new ChannelTypeUID(MqttBindingConstants.BINDING_ID, channelTypeId);
if (dimension != null) {
this.channelType = ChannelTypeBuilder.state(channelTypeUID, dimension + " Value", "Number:" + dimension)
.build();
this.channelType = ChannelTypeBuilder
.state(channelTypeUID, dimension + " Value (" + unit.toString() + ")", "Number:" + dimension)
.withUnitHint(unit.toString()).build();
}
if (attributes.retained) {