JSR223/Python:
ir.getItem("RaceItemSwitch").getState()
…is supposed to be the exact equivalent of
Rules DSL:
RaceItemSwitch.state
Yes, the event.itemState version works, and is usually usable. That’s no problem, it’s great that it works. The problem is that getItem().getState doesn’t work reliably, and it’s not obvious that it doesn’t work well until you start relying on it. It complicates things for new users for no good reason.
When you have a rule triggered by two item states, which makes decisions based on both item states, then event.itemState doesn’t cut it anymore, because you still have to read the state of the item that didn’t change… but the one that did change must be read from event.itemState because reading the item state directly is not reliable.
And that’s how you end up with this atrocity:
stateMyButton=event.itemState if event.itemName=="MyButton" else ir.getItem("MyButton").getState()
stateTestSwitch=event.itemState if event.itemName=="Test_Switch_1" else ir.getItem("Test_Switch_1").getState()
The rules seem to be running instantly. If anything they’re running too quickly – they’re executing so quickly that the item state hasn’t had time to update yet! Adding a short delay statement before reading the item statement band-aids the problem (it behaves properly) but at the expense of performance.