diff --git a/changelog.md b/changelog.md index 1297ea4..b6a63c1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ # Changelog ## Version 0.4 (working) +* Fix Point discovery to correctly map `units` facets ## Version 0.3 (17-Jun-2021) * Add Point discovery support diff --git a/novant/novant-rt/src/io/novant/point/BNovantPointDiscoveryLeaf.java b/novant/novant-rt/src/io/novant/point/BNovantPointDiscoveryLeaf.java index 82c6471..509a03f 100755 --- a/novant/novant-rt/src/io/novant/point/BNovantPointDiscoveryLeaf.java +++ b/novant/novant-rt/src/io/novant/point/BNovantPointDiscoveryLeaf.java @@ -9,16 +9,20 @@ package io.novant.point; import java.util.*; + import javax.baja.control.*; import javax.baja.nre.util.Array; import javax.baja.nre.annotations.*; import javax.baja.registry.TypeInfo; +import javax.baja.units.*; import javax.baja.status.*; import javax.baja.sys.*; import com.tridium.ndriver.discover.BNPointDiscoveryLeaf; import com.tridium.ndriver.util.SfUtil; +import io.novant.util.*; + /** * BNovantPointDiscoveryLeaf is container class for point elements to * display in point discovery pane and pass to new point callback. @@ -259,7 +263,7 @@ public void updateTarget(BComponent target) BNovantProxyExt ext = new BNovantProxyExt(); String unit = getUnit(); - if (unit.length() > 0) f = BFacets.make(f, "unit", BString.make(unit)); + if (unit.length() > 0) f = BFacets.make(f, "units", NovantUnits.get(unit)); ext.setPointId(getPointId()); p.setProxyExt(ext); diff --git a/novant/novant-rt/src/io/novant/util/NovantUnits.java b/novant/novant-rt/src/io/novant/util/NovantUnits.java new file mode 100644 index 0000000..982e6b7 --- /dev/null +++ b/novant/novant-rt/src/io/novant/util/NovantUnits.java @@ -0,0 +1,52 @@ +// +// Copyright (c) 2021, Novant LLC +// Licensed under the MIT License +// +// History: +// 21 Jul 2021 Andy Frank Creation +// + +package io.novant.util; + +import java.util.*; +import javax.baja.units.*; + +/** + * NovantUnits provides unit conversion to BUnit. + */ +public final class NovantUnits +{ + /** Lookup a BUnit by symbol, or create a new BUnit if not found. */ + public static BUnit get(String symbol) + { + if (map == null) loadMap(); + + BUnit unit = (BUnit)map.get(symbol); + if (unit == null) + { + unit = BUnit.make(symbol, symbol, BDimension.DEFAULT); + map.put(symbol, unit); + } + + return unit; + } + + /** Load reverse lookup map via UnitDatabase. */ + private static void loadMap() + { + map = new HashMap(); + UnitDatabase.Quantity[] quants = UnitDatabase.getDefault().getQuantities(); + for (int i=0; i