Why not compare to a string, “ON” that is. Otherwise you need to import the appropriate classes (and the hassle is to find out which one - it’s in the helper library docs).
Note Python is strict about item types, there’s no implicit conversion like in rules DSL there sometimes is.
I hesitate to comment too much on this sort of thing but I don’t see any benefit to adding this as a module, as currently written. In a Rule the code to test if a Switch is ON is as simple as
items[item_name] == ON
That is not significantly more complex or more typing than isON(item_name), plus you need to import isON to use it.
However, if you want to make it something more useful, make it also work with DimmerItem and ColorItems too. In that case you could get the Item from the registry and call getStateAs(OnOffType) and if the Item type supports OnOffType it will return it.
I’m having a little trouble with looking up where I’d find the appropriate packages to import - had open the link that you have mentioned, but I can’t seem to find the link between ON and its package core.jsr223.scope from there?
Coming from a Java world (stopped developing 9 years ago), I was already looking for an equivalent of the “Javadocs”, so I can dig into what exists and where to find it. Where would I find something like that?
is not so much more typing work. I prefer it because it keeps the sources a bit more readable for me. I’ve only started to use Jython, so over time, I will probably re-design my helpers quite often. Your “journey” posts are quite helpful for me at the moment - it’s just that my own journey is still ahead, i.e., I’m banging my head against the keyboard over the most basic stuff, from time to time.
Just to highlight what I was aiming at: isON is, of course, a very simplistic helper. I want the look & feel of my code to be consistent, though. What I hated most about Rules DSL is that syntax was obfuscating the meaning.
Therefore, in addition to isON, I’m also defining a bit more unorthodox helper stuff like:
report = 
report.append(u"🌟 Heute ist ")
report.append(u"❄️ VORSICHT GLATTEIS")
report.append(u"\nDraußen hat es gerade ")
report.append(u"\nPrognose für heutiges Minimum ist ")
report.append(u"🌡️ HITZE\nHeute wird es wohl heiss. Morgens die Rolläden in der Küche und im Schlafzimmer herunterlassen?")
if stateOf("Weather_Windspeed_Max_Today", ">", configuration.MIN_GUSH_SPEED_CONSIDERED_STRONG_IN_KMPH, "km/h"):
report.append(u"🌪️ VORSICHT WINDBÖEN\nHeute wohl Windgeschwindigkeiten bis zu ")
I totally understand if this looks like an overkill to you, yet this amount of “readability” is what I wanted to have.
Those you’ll find in docstrings within the scripts and modules and displayed in the documentation (second link above). If something is unclear, please mention it in the forum, open an issue, or submit a PR (very much appreciated!).
Please don’t hesitate to ask! The more Jython Q&A we get into the forum, the easier the transition will be for everyone. When people are asking questions, it usually means the docs are light in that area, so I try to get most of the answers I give in the forum added to the helper library docs too.
Personally I’m ambivalent about these sorts of efforts. Essentially what you end up creating is your own Rules language. That’s great for you. But it means that any time you want to adopt an example from somewhere else, share your code with someone else, or get help with your code, there will be an additional translation step required.
For example, if you needed help with the above Rule the first thing we would have to ask is "what the heck is isOFF, isDefined, isON?
Obviously do what makes the most sense for you. But I do worry that straying too far from “standard” sets up barriers to your ability to share your code or our ability to help you with problems in your code.
Understand, and appreciate your concerns! You’re right, I want to speed up my development by using, sort of, a “DSL”.
In any case, I consider it my own task to do the “translation work”, in both directions (adopting code of others, and wrapping it, if necessary; as well as asking for advice, providing “plain” code without my “DSL” lingo).
Yes, the documentation is what I’m struggling with. How can I figure out that
from core.jsr223.scope import ON
is needed to import ON? I feel I must be overlooking something really simple here - starting from the documentation page (which links to core.jsr223), I can’t find a way to spot that ON is in core.jsr223.scope.