I’m playing around with moving my Time of Day Rule (I may or may not propose adding it to the community library but my intent is to create a Design Patterns submission with reusable implementations of a number of the DPs where it makes sense) to my personal library. I thought I had read a section in the docs that talks about this but for the life of my I can’t find it any longer.
Let’s say I copied my timeofday Rule to my personal library folder and modified it to deal with the lack of the scope since it would now be a library. What is the expected way that this would be activated?
I see that when I reboot the file is not parsed (no long entry, no .class file created) which makes some sense as nothing is actually using it.
I put the import/reload into init.py which does seem to force it to load.
Would users need to add an init.py to their community folder to load it?
Do the files in the community folder automatically get loaded and it’s just the personal folder that behaves differently?
Should the import actually be in an init.py in the scripts folder instead?
If you are going for something that inits on OH load, you need to put something in the jsr223 folder. Honestly I would put the whole thing in there, it’s pretty small.
Personal and community are treated equal, but scripts (jsr223) and libs (lib) are not the same. Your ToD is a script, I would out it all in one file and put it in jsr223/python/community. Libs are things that can be imported anywhere and used by scripts, your ToD thing is a script that does its own thing, no interaction from the user other than setting a couple values in configuration.py (if you go that route) and adding metadata to related items.
You should not be modifying the __init__.py in the personal or community folders, they are placeholders.
If you are writing a Python package it does need to have an __init__.py file in order for Python to see that it is importable.
Originally, I put the existing ToD design pattern example under Community and planned to put the rest of them in there too. This was eventually moved to a separate directory for Script Examples, in a special directory to highlight the design pattern examples (/Script Examples/Design Patterns/). This is currently where any new ones should go. I don’t see why we couldn’t have two ToD examples, but we can figure out the best way to handle it when you submit a PR for yours.
Good timing for your post though, since last night I was experimenting with moving the Mode (ToD) example back under Community in preparation for my Area Trigger/Action post, which uses it. It’s easier and more consistent to install from Community, and the docs can still be available under Script Examples. I’m still thinking through this. If it’s a working example, I don’t see why it wouldn’t be under Community. The Community namespace is just going to get awfully crowded if there are 10 different versions of the same thing, which was one of my initial concerns that I’d voiced about the directory structure. We’re probably good for now, but as more things get submitted, we’ll need to come up with a better solution. The ultimate goal being an ExtensionService for automation (script engines, scripts, libraries, rules and rule templates).
Everything under Community should be a script or a package. For most of these packages, the code will only go into community.my_package.__init__.py. For example, autoremote.