Problem localizing temperature; classpath restriction not api

development
binding
Tags: #<Tag:0x00007f014b7f4498> #<Tag:0x00007f014b7f41a0>

(Kevin Blackham) #1

I’m using 2.4.0 snapshot. I got the onewiregpio going last night, but something is causing assumption of fahrenheit per my localization settings, when the sensors output in sysfs as celsius. I tried changing the type in OneWireGPIOHandler.java, based on this eclipse smarthome blog post.

Here’s the diff of my attempt:

--- a/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java
+++ b/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java
@@ -23,7 +23,8 @@ import java.util.stream.Stream;

 import org.apache.commons.lang.StringUtils;
 import org.eclipse.smarthome.config.core.Configuration;
-import org.eclipse.smarthome.core.library.types.DecimalType;
+import org.eclipse.smarthome.core.library.types.QuantityType;
+import org.eclipse.smarthome.core.library.unit.SIUnits;
 import org.eclipse.smarthome.core.thing.Channel;
 import org.eclipse.smarthome.core.thing.ChannelUID;
 import org.eclipse.smarthome.core.thing.Thing;
@@ -126,7 +127,7 @@ public class OneWireGPIOHandler extends BaseThingHandler {
     private void publishTemperatureSensorState(ChannelUID channelUID) {
         BigDecimal temp = readSensorTemperature(gpioBusFile);
         if (temp != null) {
-            updateState(channelUID, new DecimalType(temp));
+            updateState(channelUID, new QuantityType<Temperature>(temp, SIUnits.CELSIUS));
         }
     }

But build fails:

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile (default-compile) on project org.openhab.binding.onewiregpio: Compilation failure: Compilation failure:
[ERROR] /home/kevin/src/openhab2-addons/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java:[1]
[ERROR] /**
[ERROR] ^
[ERROR] The type javax.measure.Quantity cannot be resolved. It is indirectly referenced from required .class files
[ERROR] /home/kevin/src/openhab2-addons/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java:[1]
[ERROR] /**
[ERROR] ^
[ERROR] The type javax.measure.Unit cannot be resolved. It is indirectly referenced from required .class files
[ERROR] /home/kevin/src/openhab2-addons/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java:[1]
[ERROR] /**
[ERROR] ^
[ERROR] The type javax.measure.quantity.Temperature cannot be resolved. It is indirectly referenced from required .class files
[ERROR] /home/kevin/src/openhab2-addons/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java:[27]
[ERROR] import org.eclipse.smarthome.core.library.unit.SIUnits;
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] Access restriction: The type 'SIUnits' is not API (restriction on classpath entry '/home/kevin/.m2/repository/org/eclipse/smarthome/core/org.eclipse.smarthome.core/0.10.0-SNAPSHOT/org.eclipse.smarthome.core-0.10.0-SNAPSHOT.jar')
[ERROR] /home/kevin/src/openhab2-addons/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java:[130]
[ERROR] updateState(channelUID, new QuantityType<Temperature>(temp, SIUnits.CELSIUS));
[ERROR] ^^^^^^^^^^^
[ERROR] Temperature cannot be resolved to a type
[ERROR] /home/kevin/src/openhab2-addons/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java:[130]
[ERROR] updateState(channelUID, new QuantityType<Temperature>(temp, SIUnits.CELSIUS));
[ERROR] ^^^^^^^^^^^^^^^
[ERROR] Access restriction: The type 'SIUnits' is not API (restriction on classpath entry '/home/kevin/.m2/repository/org/eclipse/smarthome/core/org.eclipse.smarthome.core/0.10.0-SNAPSHOT/org.eclipse.smarthome.core-0.10.0-SNAPSHOT.jar')
[ERROR] /home/kevin/src/openhab2-addons/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java:[130]
[ERROR] updateState(channelUID, new QuantityType<Temperature>(temp, SIUnits.CELSIUS));
[ERROR] ^^^^^^^^^^^^^^^
[ERROR] Unit<Temperature> cannot be resolved to a type
[ERROR] /home/kevin/src/openhab2-addons/addons/binding/org.openhab.binding.onewiregpio/src/main/java/org/openhab/binding/onewiregpio/handler/OneWireGPIOHandler.java:[130]
[ERROR] updateState(channelUID, new QuantityType<Temperature>(temp, SIUnits.CELSIUS));
[ERROR] ^^^^^^^
[ERROR] Access restriction: The field 'SIUnits.CELSIUS' is not API (restriction on classpath entry '/home/kevin/.m2/repository/org/eclipse/smarthome/core/org.eclipse.smarthome.core/0.10.0-SNAPSHOT/org.eclipse.smarthome.core-0.10.0-SNAPSHOT.jar')
[ERROR] 8 problems (8 errors)

Is there an example of implementing temperature localization in an openhab addon? I’m probably doing this wrong? No other bindings in openhab2-addons declare QuantityType, but zigbee and zwave binding do. E.g. from zigbee:

updateChannelState(new QuantityType<>(BigDecimal.valueOf(value, 2), SIUnits.CELSIUS));

(Kevin Blackham) #2

Nevermind. I figured it out. Needed to update the manifest too.