Skip to content

Conversation

@cweitkamp
Copy link
Contributor

  • Expose CurrencyUnits to Scripts

Signed-off-by: Christoph Weitkamp [email protected]

Signed-off-by: Christoph Weitkamp <[email protected]>
@cweitkamp cweitkamp requested a review from a team as a code owner November 5, 2025 18:02
@dilyanpalauzov
Copy link
Contributor

This adds CurrencyUnits to the default JSR223 preset, so that afterwards new CurrencyUnit(..) can be used without explicit import org.openhab.core.library.unit.CurrencyUnits; in the JSR223 script, right?

I think the change in ScriptImplicitlyImportedTypes.java acts differently: it makes the static elements of BinaryPrefix available without (prefix) qualifier BinaryPrefix.. #5098 shows a different approach, how to do an implicit import java.time.temporal.ChronoUnit; in DSL scripts, so that afterwards ChronoUnit.DAYS can be used in scripts/rules.

With that approach the feeling of using JSR223 and DSL Script/Rules will be more consistent, as in both systems BinaryPrefix.GIBI(…) has then to be used.

@dilyanpalauzov
Copy link
Contributor

Actually openhab/core/model/script/scoping/ScriptImportSectionNamespaceScopeProvider.java already contains

public static final QualifiedName CORE_LIBRARY_UNITS_PACKAGE = QualifiedName.create(
                   "org", "openhab", "core", "library", "unit");
implicitImports.add(doCreateImportNormalizer(CORE_LIBRARY_UNITS_PACKAGE, true, false));

which corresponds in DSL scripts to import org.openhab.core.library.unit.*;. This script

for (BinaryPrefix s: BinaryPrefix.values)
    logError("A", s.toString)

prints

[ERROR] [org.openhab.core.model.script.A     ] - YOBI
[ERROR] [org.openhab.core.model.script.A     ] - ZEBI
[ERROR] [org.openhab.core.model.script.A     ] - EXBI
[ERROR] [org.openhab.core.model.script.A     ] - PEBI
[ERROR] [org.openhab.core.model.script.A     ] - TEBI
[ERROR] [org.openhab.core.model.script.A     ] - GIBI
[ERROR] [org.openhab.core.model.script.A     ] - MEBI
[ERROR] [org.openhab.core.model.script.A     ] - KIBI

I guess the CurrencyUnits prefix is also available in scripts. Isn’t this sufficient?

@kaikreuzer
Copy link
Member

@cweitkamp Could you answer @dilyanpalauzov's remarks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants