I am trying to create a rule that is triggered when Sonos cover url changes, i want to resize the image and publish it in the OpenHab static folder so its visible also from the cloud and has a proper fixed size.
I would like to use PIL library, assuming i can import it, i think the ideal approach would be to have a rule like this:
rule "Sonos Cover Resize"
Item Sonos_Current_Album_Cover_Art changed
logInfo("Sonos", "Cover changed")
var coverUrl = get value of item (figuring it out)
var resizedFile = transform("SCRIPT", "publish_image.py", coverUrl)
logInfo("Sonos new file", resizedFile)
How would publish_image.py looks like? JS and JRuby have both anonymous functions and python cannot return anything unless i define a function. Is this supported? is there another way to do this? Since i need to pass a parameter and convert an image i thought it was the right approach.
P.S. editing files via VS Code remote + OpenHab extension is JUST AWESOME
I think its not possible to use jython for transformations, i had a quick look to the addon source and it seems like there is no scopeValues method implemented so it seems parameters are just not passed to jython
Indeed not a big deal but i am not sure why Jython is a second class citizen, also if i have to download libraries i prefer to have only python ones rather than mixing JS/Gems and Python ones. I will try to dig a bit deeper in the code to understand why its not there or maybe a dev shows up and gives some hint
Jython is stuck on Python 2.7 which is now years past end of life. Python 3 support is no where in sight.
The upstream Jython project has very little activity indicating it’s all but abandonded.
No one on the OH side has volunteered to maintain the Jython add-on and the corresponding helper libraries.
If you want to use Python, the only recommendation I can offer is to use HABApp. Unless and until someone decides to develop a GraalVM Python add-on (which would be awesome!) Jython can only be considered to be deprecated. At some point, probably soon, it’s going to break and there will be nothing the OH project can do to fix it.
It’s treated like a second class citizen because it is. Maybe “zombie” would be a better metaphor.
None of the other rules languages have any of these problems and JS Scripting and jRuby have the best overall support in terms of number of users and the quality of their docs.
But, I’m not sure a transformation is the better approach here anyway. I wonder if a call out to a native Python script using executeCommandLine to do the resize and the save to disk would not be a more appropriate approach. It doesn’t feel right for a transformation to have extra side effects (i.e. saving to disk) beyond changing the the input to a different output.