|
54 | 54 | import org.slf4j.Logger;
|
55 | 55 | import org.slf4j.LoggerFactory;
|
56 | 56 |
|
57 |
| -import tech.units.indriya.AbstractUnit; |
58 |
| - |
59 | 57 | /**
|
60 | 58 | * Accepts updates to state as long as conditions are met. Support for sending fixed state if conditions are *not*
|
61 | 59 | * met.
|
@@ -776,32 +774,10 @@ protected State toState(BigDecimal value) {
|
776 | 774 | */
|
777 | 775 | protected @Nullable QuantityType<?> toSystemUnitQuantityType(State state) {
|
778 | 776 | return state instanceof QuantityType<?> quantityType && hasSystemUnit() //
|
779 |
| - ? toInvertibleUnit(quantityType, Objects.requireNonNull(systemUnit)) |
| 777 | + ? quantityType.toInvertibleUnit(Objects.requireNonNull(systemUnit)) |
780 | 778 | : null;
|
781 | 779 | }
|
782 | 780 |
|
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 |
| - |
805 | 781 | /**
|
806 | 782 | * Check if the given {@link State} is allowed. Non -allowed states are those which are a {@link QuantityType}
|
807 | 783 | * and if there is a 'systemUnit' not compatible with that.
|
|
0 commit comments