openhab-scripters / openhab-helper-libraries

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

Issues upgrading from 2.3 to 2.4 #132

Closed Rick-Jongbloed closed 5 years ago

Rick-Jongbloed commented 5 years ago

openhab-5iver commented 4 hours ago Hello, Rick... glad to see you updated! I don't use ideAlarm, so I don't have an opinion on this. But...

(But then i decided to migrate from 2.3 to 2.4 and all the stuff stopped working :-)).

... caught my eye. Was there functionality lost in the migration, or is it just a matter of setting things up again/in a different way? (sorry if I'm polluting your enhancement request with support questions πŸ™„)

@ricadelic Member Author ricadelic commented 6 minutes ago β€’ Hi Scott,

no worries of hijacking this thread. If it's going to contain useful info for others, i'll create an issue for it.

The startup trigger didn't work anymore, which i used very much. I saw you fixed it, kudos to you! πŸ’― To get around this, I implemented a file watcher and a cron job which disabled itself. This updated an item which triggered all the other rules. This kinda replicated the startup trigger.

Also i couldn't get my regular rules working, rules were using the helpers but without the decoraters like:

class rule_scene_lights_living (SimpleRule):
    def __init__(self):
        self.triggers = [ 
                            StartupTrigger(), 

                            ItemCommandTrigger("timer_rule_scene_woonkamer_new_init_hardware", command="OFF"),

                            ItemStateChangeTrigger("light_woonkamer_dimmer_boekenkast"),
                            ItemStateChangeTrigger("light_woonkamer_dimmer_vitrinekast"),
                            ItemStateChangeTrigger("switch_led_strip_tv_toggle", state="ON",previousState="OFF"),
                            ItemStateChangeTrigger("switch_groene_tl_toggle", state="ON",previousState="OFF"),
                            ItemStateChangeTrigger("switch_led_strip_tv_toggle", state="OFF",previousState="ON"),
                            ItemStateChangeTrigger("switch_groene_tl_toggle", state="OFF",previousState="ON"),

                            ItemCommandTrigger("number_scene_lights_living"),
                            ItemCommandTrigger("switch_scene_living_chill"),
                            ItemCommandTrigger("switch_scene_living_full")
                        ]

    def execute(self, module, input):
        logging.info("RULE WOONKAMER SCENE STARTED")

so i migrated them to the @rule/@when decorators to get it working. However i had a few rules that parsed the trigger name and the command that was send. I couldn't yet find a way to get command, apart from parsing the event text and taking the last bit of the array. Because these kind of little changes, it took me a while to transfer.

if "event" in input:
             trigger = str(input['event'])
             if "number_scene_lights_living" in trigger:
                 scene_number = str(input['command'])
                 logging.info("Recieved command from GUI(" + str(scene_number) + ")") 
             elif "switch_scene_living_chill" in trigger or "switch_scene_living_full" in trigger:
                 if input['command'] == OFF:
                     scene_number = "1"
             if items.timer_rule_scene_woonkamer_new_gui_set_new_scene == ON:
                     logging.info("timer is running, quitting script")
         else:
             trigger = "startup"
      do_stuff()

i changed it like

    if "number_ventilator_level_set_manual" in str(event):
        level_gui_manual = str(event).split()[-1]
        if level_gui_manual == "4":
            do_stuff()

However i would rather just have the whole object available. Or know how to retrieve this information in a better way.

Rick-Jongbloed commented 5 years ago

Moved this from #130

5iver commented 5 years ago

This kinda replicated the startup trigger.

That'll do it! Another way is to just call the rule function in the script, passing it None for the event. I added a note in the docs for this. StartupTrigger is working in S1566 and newer.

Also i couldn't get my regular rules working, rules were using the helpers but without the decoraters like:

The hello_world.py has some examples using the extensions. It looks like you just need to add the .trigger...

ItemCommandTrigger("timer_rule_scene_woonkamer_new_init_hardware", command="OFF").trigger

I couldn't yet find a way to get command

I assume you are using a command trigger... does event.itemCommand provide what you need? This is similar to receivedCommand implicit variable in the rules DSL. The name of the Item that triggered the rule is event.itemName and then if you need the Item itself, ir.getItem(event.itemName). I have this all documented in the "But how do I...?" section of the docs.

I'm glad to help here, but this would be good info for the forum in case others are having issues. Maybe we should call out to the people using lucid to get a thread going?

Rick-Jongbloed commented 5 years ago

StartupTrigger is working in S1566 and newer.

I'll test the snapshot release thx.

The hello_world.py has some examples using the extensions. It looks like you just need to add the .trigger...

I tried it again and apparently the rule generated an error due to the startuptrigger still in the script.

I have this all documented in the "But how do I...?" section of the docs.

i will look this up again and learn some new stuff, haha.

Maybe we should call out to the people using lucid to get a thread going?

Yes that would maybe be a good idea. When i have time this weekend, i'll try to make a post. If you have time earlier, feel free to use my info. Atm i need to upgrade openhab and get the startuptrigger working again. πŸ’―

5iver commented 5 years ago

@besynnerlig, I'm about to merge the JS libraries, but there will need to be some testing and tweaks. After they are polished, I plan to post an announcement about the repo/org name changes, inclusion of JS and Groovy, and migration of lucid and the other repos. So after that, since lucid was your baby, maybe you'd like to create a topic for helping people upgrade/migrate from the lucid repo?

besynnerlig commented 5 years ago

@besynnerlig, I'm about to merge the JS libraries, but there will need to be some testing and tweaks. After they are polished, I plan to post an announcement about the repo/org name changes, inclusion of JS and Groovy, and migration of lucid and the other repos. So after that, since lucid was your baby, maybe you'd like to create a topic for helping people upgrade/migrate from the lucid repo?

Sure, I can do that. At least I'll try ;)

besynnerlig commented 5 years ago

@besynnerlig, I'm about to merge the JS libraries, but there will need to be some testing and tweaks. After they are polished, I plan to post an announcement about the repo/org name changes, inclusion of JS and Groovy, and migration of lucid and the other repos. So after that, since lucid was your baby, maybe you'd like to create a topic for helping people upgrade/migrate from the lucid repo?

When it comes to ideAlarm and weatherStationUploader, they both used to have their own documentation that needs to be rewritten and put somewhere.

I see the need to define where such documentation should be put and the preferred way how to get it there. I also see the need for a "generic community script" installation documentation that describes in general terms how to install and configure any arbitrary community script in the standard way. Then the documentation for a specific community script can be kept to a minimum.

I think I'd want to have the documentation for ideAlarm and weatherStationUploader up to date before I try to start helping people to migrate.

5iver commented 5 years ago

I see the need to define where such documentation should be put and the preferred way how to get it there.

This should be linked to from the table of contents, and then everything that goes into Community gets a link.... https://github.com/openhab-scripters/openhab-helper-libraries/blob/master/Docs/Python/Community.md

I'll rework this doc a bit and get it linked up. I think this is a good place for summary info, but details can go into a readme inside the directory, linked to from this doc. WDYT? The document rewrite PR may change this.

I think I'd want to have the documentation for ideAlarm and weatherStationUploader up to date before I try to start helping people to migrate.

:+1:

besynnerlig commented 5 years ago

I see the need to define where such documentation should be put and the preferred way how to get it there.

This should be linked to from the table of contents, and then everything that goes into Community gets a link.... https://github.com/openhab-scripters/openhab-helper-libraries/blob/master/Docs/Python/Community.md

I'll rework this doc a bit and get it linked up. I think this is a good place for summary info, but details can go into a readme inside the directory, linked to from this doc. WDYT? The document rewrite PR may change this.

I think I'd want to have the documentation for ideAlarm and weatherStationUploader up to date before I try to start helping people to migrate.

πŸ‘

Thanks. Just to get started, I added 2 community script entries in a separate branch in my own fork, planning to submit a PR later.

Shouldn't the entries be sorted in some way (like in alphabetical order or so)? Can I propose that in my PR?

Previous entries are linking to the main scripts py-file. That will not be the case for my two entries. One of them even had a 12 page wiki assigned to it. I'll have to rework it into multiple md files instead.

Can I suggest that all community scripts should have a Docs folder in it's "root folder" (not in the lib, nor in the jsr223 folders) together with at least a single README.md file?

If we can sort this out first I'll start working with the documentation for my two entries. ;)

Rick-Jongbloed commented 5 years ago

You guys can close this issue whenever you feel suit. I received several guidelines which i implemented, thanks for this! When i run into another issue where i think it's a question, i'll create a thread on the forum.

5iver commented 5 years ago

:+1: