CrazyIvan359 / openhab-helper-libraries

JSR223-Jython scripts and modules for use with openHAB
Eclipse Public License 1.0
17 stars 5 forks source link

Use Semantics action #10

Closed jowi24 closed 3 years ago

jowi24 commented 3 years ago

Is your feature request related to a problem? Please describe. OH3 exposes a new action called "Semantics" to access attributes of the new OH3 semantic model, e.g. locations, equipments, points... I tried to use that action in Jython but it failed out of the box (see below).

Describe the solution you'd like It would be great to use Sematics action like other actions: from core.actions import Semantics ... locationItem = Semantics.getLocation(pointItem)

Describe alternatives you've considered I tried to import the action directly, but failed: from org.openhab.core.model.script.actions import Semantics Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/personal/tests.py': ImportError: cannot import name Semantics

Additional context Do you know what steps are required to use that new action? Is it required to extend automation/lib/python/core/actions.py?

CrazyIvan359 commented 3 years ago

I'm not familiar with this action, but the actions don't really need much help from the libraries. I'm going to guess it's an openHAB Core action so we'd need to add it in actions.py as you suggest.

CrazyIvan359 commented 3 years ago

Looks like it's a service, not an action, that makes it a little harder. There is already a service getter in the OSGi module of the libraries, a new semantics.py file could be created and a wrapper added to acquire and interface to this service.

jowi24 commented 3 years ago

Thank you for commenting my question. I realized that the Semantics action I tried to import is not yet avaible in https://github.com/openhab/openhab-core/tree/3.0.x but only in OH master branch... Thats why I failed :-(

CrazyIvan359 commented 3 years ago

If you can find the action code itself and give me a link I can check if you will be able to use it without modifying the libraries.

jowi24 commented 3 years ago

I just upgraded to OpenHAB 3.1.0M2 milestone release and could succesfully use the following code without need to modify your library :-)

from org.openhab.core.model.script.actions import Semantics locationItem = Semantics.getLocation(pointItem)

Thanks for your help!

CrazyIvan359 commented 3 years ago

I will add this to the core/actions.py module so that it can be use as simply from core.actions import Semantics

janwo commented 3 years ago

I will add this to the core/actions.py module so that it can be use as simply from core.actions import Semantics

This works for me already. I have cloned the current branch.

CrazyIvan359 commented 3 years ago

@janwo are you using from actions import semantics or from core.actions import semantics?

janwo commented 3 years ago

from core.actions import semantics