This description is specific for new bindings targetted for openHAB 3 or not yet merged when we switch the main branch over to openHAB 3 or bindings not part of the openHAB-addons repo. See also the post of Kai below.
As you may have read in the announcement of the 2.5.8 release, openHAB 3 is on the horizon. A big version number suggests big changes. So what does this mean for binding development. In short: not whole lot. Because the core binding interface functionality hasn’t changed much since 2.5. But there are some changes that cause bindings compiled for 2.5 not work for 3.0 and the other way around. So you need to make some changes to make your binding compile and run on openHAB 3.
So what did change related to binding development?
Java 11
openHAB 3 will require Java 11 (No older or newer version). Therefor you need to install and use Java 11 in your Eclipse (or other) IDE in order to be able to run openHAB 3. The easiest is to do a new installation of Eclipse with the Eclipse installer and select 3.0 as branch on openHAB configuration in the installer. During installation make sure to select Java 11 (In 2 places. currently the installer will ask for the java 8 environment, but you can simply select java 11). If you build on the command line with maven also make sure you maven uses the correct Java version in case you run both Java 8 and 11. It should be possible to have 2 Java versions installed, but you need to make sure to set the right path for the specific Java version when you run maven.
Namespace change of openHAB core classes
With the migration of Eclipse Smart Home to openHAB the namespace of all classes in openHAB core needed to be changed. This means all imports done by bindings that refer to org.eclipse.smarthome
have been changed to org.openhab.core
. With your binding code you can simply do a file level replace of this text string in the java source files to migrate the binding. On linux you can use the following commands in you src/main/java
directory:
find . -name *.java -exec sed -i "s/org.eclipse.smarthome.core/org.openhab.core/g" {} \;
find . -name *.java -exec sed -i "s/org.eclipse.smarthome/org.openhab.core/g" {} \;
(2 commands are needed because all classes where moved to core, but some where already in core and thus would be moved incorrectly if the second command would be done first).
Additional the class SmartHomeUnits
has been renamed to Units
. You can globally replace it with:
find . -name *.java -exec sed -i "s/SmartHomeUnits/Units/g" {} \;
ESH-INF renamed to OH-INF
The resources directory ESH-INF
of the xml files located in src/main/resources
has been renamed to OH-INF
. You can simply change this by renaming this directory.
Migrate to JUnit 5
Part of the changes in openHAB 3 is the upgrade of the unit tests to JUnit 5. Therefor if you have any unit tests these should be migrated to JUnit 5. There are some differences between JUnit 4 and 5, like import changes and the message in asserts moved from first parameter to the last.
With these changes in place you should be able to start developing bindings for openHAB 3 and also test drive the new user interface.