openhab-scripters / openhab-helper-libraries

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

Problem with the EchoThing example #10

Closed bodiroga closed 6 years ago

bodiroga commented 6 years ago

Hi @steve-bate and @spacemanspiff2007!

I know that you guys are busy, but I can't make the EchoThing example work, so any hint would be very helpful :+1:

I have placed all 000_Jython*.py files (JythonBindingInfoProvider, JythonExtensionProvider, JythonItemProvider, JythonThingProvider, JythonThingTypeProvider, JythonTransform) in the /etc/openhab2/automation/jsr223/000_Components folder and I can see in openhab's log file that the files are correctly parsed. The next step was to create the 100_EchoThing.py file and, even if the file is detected by openHAB, the following error can be seeing in the log file:

2017-12-12 12:49:49.511 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/100_EchoThing.py': AttributeError: 'module' object has no attribute 'JythonThingTypeProvider' in <script> at line number 95

The 95th line is where the script tries to add the ThingTypeProvider, but the error indicates that the "openhab" module (import openhab) is not correctly fulfilled with the JythonThingTypeProvider attribute. That should be done at line 25 of the 000_JythonThingTypeProvider.py file (openhab.JythonThingTypeProvider = JythonThingTypeProvider()).

Can anyone confirm if I am the only one having the error? Can you reproduce it?

Sorry for bothering you and many thanks for your help,

Aitor

steve-bate commented 6 years ago

This is experimental code, but this aspect of it should be normal Python. If the name was set successfully in the openhab module by the JythonBindingInfoProvider then it should be available when that module is imported elsewhere. I'm assuming you have verified the load order is correct (provider before thing definition). In the thing definition you could try logging the names in the openhab module (using, dir(openhab), for example) to get some clues.

bodiroga commented 6 years ago

Good morning @steve-bate!

I don't see any issue in the loading order, here you can see the content of my log file:

2017-12-14 08:50:53.264 [INFO ] [.internal.GenericScriptEngineFactory] - Activated scripting support for ECMAScript 2017-12-14 08:50:53.275 [INFO ] [.internal.GenericScriptEngineFactory] - Activated scripting support for python 2017-12-14 08:50:54.934 [WARN ] [g.eclipse.smarthome.core.net.NetUtil] - Found multiple local interfaces - ignoring 10.15.181.95 2017-12-14 08:50:54.965 [WARN ] [g.eclipse.smarthome.core.net.NetUtil] - Found multiple local interfaces - ignoring 10.15.181.95 2017-12-14 08:50:55.036 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://10.15.181.132:8080 2017-12-14 08:50:55.037 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://10.15.181.132:8443 2017-12-14 08:50:58.595 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'test.items' 2017-12-14 08:51:00.145 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007 2017-12-14 08:51:01.639 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app 2017-12-14 08:51:01.712 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui 2017-12-14 08:51:01.776 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel 2017-12-14 08:51:18.392 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_Components/000_JythonBindingInfoProvider.py' 2017-12-14 08:51:21.507 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_Components/000_JythonExtensionProvider.py' 2017-12-14 08:51:23.274 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_Components/000_JythonItemProvider.py' 2017-12-14 08:51:24.610 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_Components/000_JythonThingProvider.py' 2017-12-14 08:51:25.805 [ERROR] [JythonThingProvider ] - ['JythonThingProvider', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_item_getattr', 'items', 'jsr223', 'log', 'osgi'] 2017-12-14 08:51:25.812 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_Components/000_JythonThingTypeProvider.py' 2017-12-14 08:51:26.836 [ERROR] [JythonThingTypeProvider ] - ['JythonThingTypeProvider', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_item_getattr', 'items', 'jsr223', 'log'] 2017-12-14 08:51:26.871 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_Components/000_JythonTransform.py' 2017-12-14 08:51:27.785 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '100_EchoThing.py' 2017-12-14 08:51:28.903 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/100_EchoThing.py': AttributeError: 'module' object has no attribute 'JythonThingTypeProvider' in <script> at line number 95

But you are indeed right, the different Jython*Providers methods are not correctly added to the openhab module :confused: The JythonThingProvider and JythonThingTypeProvider error log messages that you see are added by me, using the line:

logging.getLogger("JythonThingProvider").error(dir(openhab))

in each file.

Even if the JythonThingProvider seems to be added, in the JythonThingTypeProvider log entry that method is lost :thinking:

I will try to increase the log level and report back, let's see if we can use this issues to improve the documentation :+1:

Best regards,

Aitor

bodiroga commented 6 years ago

Hi @steve-bate!

Does closing the issue mean that you have tried it again and you are not able to reproduce the problem? Has anyone else tried the EchoThing example? I haven't been able to fix it :cry:

Thanks again and best regards,

Aitor