openhab-scripters / openhab-helper-libraries

Scripts and modules for use with openHAB
Eclipse Public License 1.0
88 stars 70 forks source link

Fix string triggers and UUIDs #143

Closed 5iver closed 5 years ago

5iver commented 5 years ago

Triggers for StringItems that used a new_state or old_state could have invalid characters for the Trigger UUIDs, which was raising an exception in the validation. This PR corrects that, and also allows for states and Channel triggers with spaces in them. While working this PR, I could see extreme edge cases where the Trigger UUIDs were not unique and the Triggers would overwrite themselves. To prevent this, all Trigger names now have generated UUIDs appended to them.

You can specify a StringItem's state with the following formats. This is only necessary if the state or Channel trigger has spaces in it.

@when("Item Virtual_String_1 changed from 'this is a test' to 'this is another test'") @when("Item Virtual_String_1 changed from \"this is a test\" to \"this is another test\"") @when('Item Virtual_String_1 changed from "this is a test" to "this is another test"') @when('Item Virtual_String_1 changed from \'this is a test\' to \'this is another test\'')

Fixes #141

Signed-off-by: Scott Rushworth openhab@5iver.com

5iver commented 5 years ago

@besynnerlig, @mjcumming, @ScottKinSF, @CrazyIvan359 , I've tested this pretty well and all of my rules loaded properly, but I prefer at least a second pair of eyes on anything in core.rules or core.triggers. Could one of you please take a look and try this out?

@tavalin, this should resolve your issue, so maybe you could test it out too?

CrazyIvan359 commented 5 years ago

~@openhab-5iver so I built my dev instance finally... test did not go well though:~ If I had not rushed I would have remembered to add this PR to my dev instance. New code works perfectly.

mjcumming commented 5 years ago

@openhab-5iver I might have sometime over the coming days - My install is 2.4 or do I need to test against 2.5M1?

5iver commented 5 years ago

My install is 2.4 or do I need to test against 2.5M1?

The entire repo is compatible with 2.4, but the custom module handlers (like StartupTrigger) won't work unless you are on a snapshot or 2.5M2 (when it comes out). If you already have everything else up to date, just replace your triggers.py with this.

tavalin commented 5 years ago

@openhab-5iver works for me. I've now ported over my first 2 rules to jsr223 👍

More to come in the future...

5iver commented 5 years ago

Thank you!