Jython Drop-in Replacement for Expire 1.x Binding

The PR is a branch on Rich’s fork, you need to add his fork as a remote and pull that branch:

git remote add rich https://github.com/rkoshak/openhab-helper-libraries.git
git fetch rich
git checkout -t rich/expire

The linked instructions are for someone with write access.

1 Like

I tried:

git init
Initialized empty Git repository in /etc/openhab2/bwo/.git/

git remote add rich https://github.com/rkoshak/openhab-helper-libraries.git

git checkout -t rich/expire
fatal: 'rich/expire' is not a commit and a branch 'expire' cannot be created from it


Oops, you’ll need to do a git fetch in between, I’ll update my instructions

I may give it a try later. I fetched OK but it looks the same as what I tried.
This line is the issue.
from org.openhab.core.library.items import StringItem

OH cannot find org.openhab.core.library.items

Remove that line. I’m messing with this script today and that import isn’t used. It’s giving you an error because org.openhab.core is only present if you have compat1.x installed.

1 Like

Please add a comment to the github and I’ll come back later today or tomorrow to take a look. I assumed that these have moved from org.eclipse as part of the great merge earlier this year. But if I’m indeed not using it there is no reason for the import to be there.

1 Like

Done

1 Like

The current version of openhab still uses the eclipse namespace despite the merge.

I spent some time implementing and modify this script on the weekend. I will be making a PR on your branch when I have time. I added the live reload handling I think I suggested on the past as a hold over until we have item registry triggers. This required restructuring the expire rule and trigger generator to be dynamic.

2 Likes

OK, I got back to testing on a clean 2.5 Milestone 4 install. I removed the unneeded line and now get a different error.

2019-11-03 14:01:07.602 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/community/expire/expire.py': AttributeError: 'function' object has no attribute 'triggers' in <script> at line number 179

Do you have any items setup for expire?

Not when I posted that log. I now have one using the Expire binding though.

Yes that log is saying that the trigger generator function did not make any triggers (because no valid configurations exist). If you now have a valid configuration on an item you should remove the expire binding and restart openhab. When I first switched over to it the fact that expire binding was installed cause openhab to treat the expire metadata as not metadata so the script can’t see it until you restart.

Ok I will try.
So the binding should check for the condition when there are no timers yet.

The binding called Expire must be removed and then you must restart openhab. After that, this script called Expire will be able to see the expire metadata. If you have correctly configured expire metadata this script will monitor them and create timers as necessary.

I installed your PR version. It appears to work now but the debug log seems to show a warning.

2019-11-03 18:15:27.942 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/community/expire/expire.py'

2019-11-03 18:15:36.471 [DEBUG] [jsr223.jython.Expire Init           ] - No value for 'expire_reload_item' in configuration.py, using default item 'expire_reload'

2019-11-03 18:15:36.494 [DEBUG] [jsr223.jython.Expire Init           ] - Unable to create Expire Reload rule, item 'expire_reload' does not exist

2019-11-03 18:15:36.508 [DEBUG] [jsr223.jython.Expire Load           ] - Expire loading...

2019-11-03 18:15:36.716 [DEBUG] [jsr223.jython.Expire Load           ] - Expire configured for 'PapTimer' with timeout 0:05:00 to command 'OFF'

Read the comments I put in the PR. Also thank you for testing it.

This log entry:

[DEBUG] [jsr223.jython.Expire Init           ] - Unable to create Expire Reload rule, item 'expire_reload' does not exist

Is intentionally put under DEBUG not WARN because it is not really an error. The reload item is an optional function of this script because there is currently no way to listen for Item added, Item removed, or Item changed events. If you don’t have a reload item specified in configuration.py then the absence of the default item is not an error.

1 Like