added support for QuantityType in the compatibility layer (#319)

This specifically makes the QuantityType backward compatible and makes it treated as a simple DecimalType in any 1.x add-ons, such as specifically the persistence services.

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer 2018-03-26 14:29:19 +02:00 committed by GitHub
parent bd654a60e6
commit 9b0bf26c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 1 deletions

View File

@ -8,12 +8,16 @@ Bundle-Version: 2.3.0.qualifier
Fragment-Host: org.openhab.core.compat1x
Import-Package:
groovy.lang,
javax.measure.quantity,
org.codehaus.groovy.reflection,
org.codehaus.groovy.runtime,
org.codehaus.groovy.runtime.callsite,
org.codehaus.groovy.runtime.typehandling,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.core.events,
org.eclipse.smarthome.core.library.types,
org.eclipse.smarthome.test,
org.hamcrest;core=split,
org.junit
org.junit,
tec.uom.lib.common,
tec.uom.se

View File

@ -10,6 +10,10 @@ package org.openhab.core.compat1x.internal;
import static org.junit.Assert.assertEquals;
import javax.measure.quantity.Temperature;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.junit.Test;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.library.tel.types.CallType;
@ -29,4 +33,11 @@ public class TypeMapperTest {
CallType ohType2 = (CallType) TypeMapper.mapToOpenHABType(TypeMapper.mapToESHType(ohType1));
assertEquals(ohType1, ohType2);
}
@Test
public void testQuantityType() {
QuantityType<Temperature> eshType1 = new QuantityType<>("10 °C");
DecimalType eshType2 = (DecimalType) TypeMapper.mapToESHType(TypeMapper.mapToOpenHABType(eshType1));
assertEquals(eshType1.as(DecimalType.class), eshType2);
}
}

View File

@ -65,6 +65,7 @@ Export-Package:
org.openhab.ui.items
Import-Package:
com.google.common.base,
javax.measure,
javax.servlet,
javax.servlet.http,
javax.sound.sampled,

View File

@ -20,6 +20,7 @@ import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.library.types.PointType;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.library.types.StopMoveType;
import org.eclipse.smarthome.core.library.types.StringListType;
import org.eclipse.smarthome.core.library.types.StringType;
@ -69,6 +70,8 @@ public class TypeMapper {
result = new org.openhab.core.library.types.StringType(type.toString());
} else if (typeClass.equals(DecimalType.class)) {
result = new org.openhab.core.library.types.DecimalType(type.toString());
} else if (typeClass.equals(QuantityType.class)) {
result = new org.openhab.core.library.types.DecimalType(((QuantityType<?>) type).toBigDecimal());
} else if (typeClass.equals(HSBType.class)) {
result = new org.openhab.core.library.types.HSBType(type.toString());
} else if (typeClass.equals(PercentType.class)) {