Skip to content

Commit

Permalink
[knx] Fix fallback to DecimalType in number conversion
Browse files Browse the repository at this point in the history
Carryover from smarthomej/addons#279.

Also-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
  • Loading branch information
holgerfriedrich committed Mar 8, 2023
1 parent 993cebc commit 5f0feb9
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,21 @@ private static Type handleDpt10(String value) throws ParseException {
if (allowedTypes.contains(PercentType.class)
&& (HSBType.class.equals(preferredType) || PercentType.class.equals(preferredType))) {
return new PercentType(BigDecimal.valueOf(Math.round(value)));
} else if (allowedTypes.contains(QuantityType.class) && !DISABLE_UOM) {
}

if (allowedTypes.contains(QuantityType.class) && !DISABLE_UOM) {
String unit = DPTUnits.getUnitForDpt(id);
if (unit != null) {
return new QuantityType<>(value + " " + unit);
} else {
LOGGER.trace("Could not determine unit for DPT '{}', fallback to plain decimal", id);
}
} else if (allowedTypes.contains(DecimalType.class)) {
}

if (allowedTypes.contains(DecimalType.class)) {
return new DecimalType(value);
}

LOGGER.warn("Failed to convert '{}' (DPT '{}'): no matching type found", value, id);
return null;
}
Expand Down

0 comments on commit 5f0feb9

Please sign in to comment.