[automation] Make quantity types available in scripts (#1940)
Fixes #1763 Signed-off-by: Kai Kreuzer <kai@openhab.org>pull/1947/head
parent
2b9f890831
commit
ad189bd4f1
|
@ -33,6 +33,7 @@ Import-Package: \
|
|||
org.openhab.core.model.script.engine.action,\
|
||||
com.google.common.base;version="14",\
|
||||
javax.measure,\
|
||||
javax.measure.quantity,\
|
||||
org.eclipse.jdt.annotation;resolution:=optional,\
|
||||
org.eclipse.xtext.xbase.lib,\
|
||||
org.osgi.*,\
|
||||
|
|
|
@ -43,7 +43,8 @@ Import-Package: \
|
|||
org.openhab.core.io.net.http,\
|
||||
org.openhab.core.model.core,\
|
||||
com.google.common.*;version="14",\
|
||||
javax.measure.*,\
|
||||
javax.measure,\
|
||||
javax.measure.quantity,\
|
||||
org.apache.*,\
|
||||
org.eclipse.jdt.annotation;resolution:=optional,\
|
||||
org.eclipse.jetty.http.*,\
|
||||
|
|
|
@ -35,6 +35,7 @@ public class ScriptImportSectionNamespaceScopeProvider extends XImportSectionNam
|
|||
public static final QualifiedName MODEL_SCRIPT_ACTIONS_PACKAGE = QualifiedName.create("org", "openhab", "core",
|
||||
"model", "script", "actions");
|
||||
public static final QualifiedName TIME_PACKAGE = QualifiedName.create("java", "time");
|
||||
public static final QualifiedName QUANTITY_PACKAGE = QualifiedName.create("javax", "measure", "quantity");
|
||||
|
||||
@Override
|
||||
protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) {
|
||||
|
@ -46,6 +47,7 @@ public class ScriptImportSectionNamespaceScopeProvider extends XImportSectionNam
|
|||
implicitImports.add(doCreateImportNormalizer(CORE_PERSISTENCE_PACKAGE, true, false));
|
||||
implicitImports.add(doCreateImportNormalizer(MODEL_SCRIPT_ACTIONS_PACKAGE, true, false));
|
||||
implicitImports.add(doCreateImportNormalizer(TIME_PACKAGE, true, false));
|
||||
implicitImports.add(doCreateImportNormalizer(QUANTITY_PACKAGE, true, false));
|
||||
return implicitImports;
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,9 @@ public class ScriptEngineOSGiTest extends JavaOSGiTest {
|
|||
Item numberItem = itemRegistry.get(NUMBER_ITEM_LENGTH);
|
||||
((NumberItem) numberItem).setState(new QuantityType<>("1 m"));
|
||||
|
||||
assertThat((QuantityType<?>) runScript("val length = NumberC.state as QuantityType; return length / 2|cm;"),
|
||||
assertThat(
|
||||
(QuantityType<?>) runScript(
|
||||
"val length = NumberC.state as QuantityType<Length>; return length / 2|cm;"),
|
||||
is(QuantityType.valueOf("50")));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue