Amending existing binding code - what is the "right" way to install it?

I’m working on changes to denonmarantz binding but I’m struggling to find in documentation what’s the best way to develop code in an existing binding.

My setup: openHAB installed on raspbian on raspberry pi, so there is a kar file in the system with all add-ons, including the one I’m trying to improve. The system kar file is in /usr/share/openhab/addons/openhab-addons-3.4.2.kar. For code development I use vim+syntastic on a fedora linux (a separate machine)

What I did so far:

  1. Cloned openhab-addons, modified and compiled the code, so I generated org.openhab.binding.denonmarantz-3.4.2.jar file.
  2. Copied the file to /usr/share/openhab/addons/ on the raspbian/openhab machine.
  3. Renamed jar to kar
  4. I tried to install it with
kar:install file:///usr/share/openhab/addons/org.openhab.binding.denonmarantz-3.4.2.kar


install file:///usr/share/openhab/addons/org.openhab.binding.denonmarantz-3.4.2.kar

The commands doesn’t generate any output or errors, but nothing seems to be changing in the system.
I don’t see any new binding.

Now the question: how can I install the modified extension? Should I change the version for the modified binding? Change the name? Create a copy with a new name?

There is definitely something obvious that I’m missing. Any advice or hint how to proceed would be welcome!

P.S. I read about setting the IDE but it doesn’t say how to install the developed code. Maybe Eclipse does that part, but I prefer simple bulletproof tools.

Updating existing binding can go in selective way. If you have a build which does not change dependencies then:

openhab> la -s|grep -i astro
286 | Active   |  80 x 3.0.2                   | org.openhab.binding.astro
openhab> update 286 file:/some/file/in/my/filesystem/created-by-me.jar
openhab> la -l|grep -i astro
286 | Active   |  80 x 3.0.2                   | file:/some/file/in/my/filesystem/created-by-me.jar

Above way updates just sinlge line. Command in line 1 allows to find module id (286 in above example). The update call in third line tells to load another file for that module. Command in fourth line confirms that updated location is accepted. You can notice that there are two switches -s which prints module name and -l which prints its update location.

Update location is retained across restarts, so subsequent updates can be done with update 286. You need to specify update location only if you change it.


Thanks! I t works slightly different for me - I’ll provide a detailed info later on (file path is not shown after installation).

This is very handy to know.

  1. If you updated the jar file, do you need to call update again? Won’t it detect the changes automatically?

  2. How can we revert back to the original binding / jar?

1 Like

Thanks for help Łukasz! I have a first working version of the amended denonmatantz binding :nerd_face:
Lessons learned:

  1. la is the same as bundle:list
  2. to point to a file one had to use file:// prefix
  3. no need to rename jar to kar
  4. diag can help with diagnosing problems with binding installation
  5. if you get bundle status other than Active it probably makes sense to remove is (from GUI), install again (form GUI) and then update the modified version on top of it.
  6. Once the setup is fixed the process of developing (code change, compile, deploy) takes a few seconds. I use scp to copy the file over the the openhab machine.

Each call of update command copies contents of referenced file into userdata/cache directory. As long as you do not do a “clean” start of openHAB you do not need to worry about reset. Also update of file does not affect contents of storage directory, unless you call update again.
In order to revert to previously known state you can do update xyz mvn:org.openhab.addons/abc/version. This will simply fetch a abc module from runtime/system directory.
Long story short - when you download openHAB you have copy of everything in runtime/system directory. When you launch it for first time its size almost doubles, cause major part of runtime contents gets copied to userdata/cache to retain actual runtime state.

1 Like

For future use:
My setup: a laptop for coding & compiling, rpi running openHUB.

  1. git clone GitHub - openhab/openhab-addons: Add-ons for openHAB
  2. find the binding to work on, in my case it’s in openhab-addons/bundles/org.openhab.binding.denonmarantz
  3. compile the binding without any code changes to make sure the compilation works OK
mvn clean install -pl :org.openhab.binding.denonmarantz
  1. On compiling errors first check java --version and mvn --version and make sure it’s all OK with the versions
  2. Make changes or apply patches
  3. Compile again
  4. Successful compilation producer jar file in the target directory. In my case in openhab-addons/bundles/org.openhab.binding.denonmarantz/target and the file is called org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar
  5. Transfer the file to the hardware running openhab to /usr/share/openhab/addons/ (on raspbian)
    9 Change the ownership of the file with
sudo chown openhab:openhab org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar
  1. log in openHAB console with ssh -p 8101 openhab@localhost
  2. search for the binding:
openhab> la -s|grep -i denonmarantz
237 │ Active   │  80 │ 4.0.1                  │ org.openhab.binding.denonmarantz
245 │ Active   │  80 │     │ org.openhab.binding.denonmarantz
  1. check the files (one is the original one, one is modified):
openhab> la -l|grep -i denonmarantz
237 │ Active   │  80 │ 4.0.1                  │ mvn:org.openhab.addons.bundles/org.openhab.binding.denonmarantz/4.0.1
245 │ Active   │  80 │     │ file:/usr/share/openhab/addons/org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar

13 Uninstall the original binding and check it’s removed:

openhab> uninstall 237
openhab> la -s|grep -i denonmarantz
245 │ Active   │  80 │     │ org.openhab.binding.denonmarantz
openhab> la -l|grep -i denonmarantz                                                                                                                                                           
245 │ Active   │  80 │     │ file:/usr/share/openhab/addons/org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar
  1. I run update (looks like OH3 might behave in a different way than OH4:
update 245 file:/usr/share/openhab/addons/org.openhab.binding.denonmarantz-4.1.0-SNAPSHOT.jar
  1. Enjoy!
1 Like