Skip to content

Commit 94313ba

Browse files
authored
remove duplicate code (openhab#18270)
Signed-off-by: Andrew Fiddian-Green <[email protected]>
1 parent 40a6334 commit 94313ba

File tree

1 file changed

+1
-25
lines changed
  • bundles/org.openhab.transform.basicprofiles/src/main/java/org/openhab/transform/basicprofiles/internal/profiles

1 file changed

+1
-25
lines changed

bundles/org.openhab.transform.basicprofiles/src/main/java/org/openhab/transform/basicprofiles/internal/profiles/StateFilterProfile.java

+1-25
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
import org.slf4j.Logger;
5555
import org.slf4j.LoggerFactory;
5656

57-
import tech.units.indriya.AbstractUnit;
58-
5957
/**
6058
* Accepts updates to state as long as conditions are met. Support for sending fixed state if conditions are *not*
6159
* met.
@@ -776,32 +774,10 @@ protected State toState(BigDecimal value) {
776774
*/
777775
protected @Nullable QuantityType<?> toSystemUnitQuantityType(State state) {
778776
return state instanceof QuantityType<?> quantityType && hasSystemUnit() //
779-
? toInvertibleUnit(quantityType, Objects.requireNonNull(systemUnit))
777+
? quantityType.toInvertibleUnit(Objects.requireNonNull(systemUnit))
780778
: null;
781779
}
782780

783-
/**
784-
* Convert the given {@link QuantityType} to an equivalent based on the target {@link Unit}. The conversion can be
785-
* made to both inverted and non-inverted units, so invertible type conversions (e.g. Mirek <=> Kelvin) are
786-
* supported.
787-
* <p>
788-
* Note: we can use {@link QuantityType.toInvertibleUnit()} if OH Core PR #4561 is merged.
789-
*
790-
* @param source the {@link QuantityType} to be converted.
791-
* @param targetUnit the {@link Unit} to convert to.
792-
*
793-
* @return a new {@link QuantityType} based on 'systemUnit' or null.
794-
*/
795-
protected @Nullable QuantityType<?> toInvertibleUnit(QuantityType<?> source, Unit<?> targetUnit) {
796-
Unit<?> sourceSystemUnit = source.getUnit().getSystemUnit();
797-
if (!targetUnit.equals(sourceSystemUnit) && !targetUnit.isCompatible(AbstractUnit.ONE)
798-
&& sourceSystemUnit.inverse().isCompatible(targetUnit)) {
799-
QuantityType<?> sourceInItsSystemUnit = source.toUnit(sourceSystemUnit);
800-
return sourceInItsSystemUnit != null ? sourceInItsSystemUnit.inverse().toUnit(targetUnit) : null;
801-
}
802-
return source.toUnit(targetUnit);
803-
}
804-
805781
/**
806782
* Check if the given {@link State} is allowed. Non -allowed states are those which are a {@link QuantityType}
807783
* and if there is a 'systemUnit' not compatible with that.

0 commit comments

Comments
 (0)