openhab-scripters / openhab-helper-libraries

Scripts and modules for use with openHAB
Eclipse Public License 1.0
88 stars 69 forks source link

Py scripts not loading at OH startup #316

Closed wawa79 closed 4 years ago

wawa79 commented 4 years ago

Bug description I followed the installation procedure and got it barely working except that py scripts (typically the hello_world.py script) are not loaded/executed by OH until I make a change and save the file.

Expected behavior Scripts should load on OH startup to ensure correct recovery after failure of OH system.

Logs On OH startup:

    2020-05-20 14:30:57.628 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Initialized a generic ScriptEngineFactory for jython (2.7.0): supports python (2.7) with file extensions [py], names [python, jython], and mimetypes [text/python, application/python, text/x-python, application/x-python]
    2020-05-20 14:30:58.581 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Initialized a custom ScriptEngineFactory for Oracle Nashorn (1.8.0_191): supports ECMAScript (ECMA - 262 Edition 5.1) with file extensions [js], names [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], and mimetypes [application/javascript, application/ecmascript, text/javascript, text/ecmascript]
    2020-05-20 14:30:58.581 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Removed GenericScriptEngineFactory
    2020-05-20 14:30:58.581 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Removed NashornScriptEngineFactory
    2020-05-20 14:30:58.597 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Initialized a generic ScriptEngineFactory for jython (2.7.0): supports python (2.7) with file extensions [py], names [python, jython], and mimetypes [text/python, application/python, text/x-python, application/x-python]
    2020-05-20 14:30:58.628 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Initialized a custom ScriptEngineFactory for Oracle Nashorn (1.8.0_191): supports ECMAScript (ECMA - 262 Edition 5.1) with file extensions [js], names [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], and mimetypes [application/javascript, application/ecmascript, text/javascript, text/ecmascript]

And nothing else until I make a change in the py file. Then, after the file is modified and saved:

2020-05-20 14:43:43.383 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/personal/hello_world.py'
2020-05-20 14:43:43.387 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/C:/Bin/openHAB/current/conf/automation/jsr223/python/personal/hello_world.py
2020-05-20 14:43:51.348 [DEBUG] [jsr223.jython.core.triggers         ] - when: target=[Time cron 0/10 * * * * ?], target_type=Time, trigger_target=cron, trigger_type=0/10 * * * * ?, old_state=None, new_state=None
2020-05-20 14:43:54.937 [DEBUG] [jsr223.jython.core.triggers         ] - when: Created cron_trigger: [Time_cron_0_10_8eccff409a9711ea945ff3caa20364c4]
2020-05-20 14:43:54.943 [DEBUG] [jsr223.jython.core.rules            ] - Added rule [Jython Hello World (cron decorators)]
2020-05-20 14:43:55.000 [DEBUG] [le.handler.GenericCronTriggerHandler] - Scheduled cron job '0/10 * * * * ?' for trigger 'Time_cron_0_10_8eccff409a9711ea945ff3caa20364c4_90db45cf9a9711eab8a3f3caa20364c4'.
2020-05-20 14:44:01.002 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger 'Time_cron_0_10_8eccff409a9711ea945ff3caa20364c4_90db45cf9a9711eab8a3f3caa20364c4' of rule '311a3598-1fb7-4187-8abe-9e23ce2ed528' is triggered.
2020-05-20 14:44:01.013 [INFO ] [Jython Hello World (cron decorators)] - Hello World modified!
2020-05-20 14:44:01.014 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule '311a3598-1fb7-4187-8abe-9e23ce2ed528' is executed.

Environment (please complete the following information):

Additional context Tried with JAVA_TOOL_OPTIONS / EXTRA_JAVA_OPTS variable set with a SET ENV in Windows. No change done in startup.bat. hello_world.py located in C:...ohFolder\conf\automation\jsr223\python\personal

5iver commented 4 years ago

This was an issue in OHC that has been fixed for the OH 3.0 release. I've made a jar with the fix for OH 2.5.x...

https://community.openhab.org/t/jsr223-jython-simplified-rule-definition-similar-to-rules-dsl-and-universal-decorator/53252/202?u=5iver

wawa79 commented 4 years ago

Great, thank you! But it might be helpful to reference your in the doc as I did not find it by myself.

5iver commented 4 years ago

Good idea... I'll add it to the first page of the docs with the other version specific info.