-
Notifications
You must be signed in to change notification settings - Fork 421
fix async constraints #950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
does the async constraint work with listen_state? i think its pretty useless to have the ability to sleep inside a constaint. |
I dont't see any difference between awaiting sleep and awaiting listen_state, so it probably does. I don't see why anybody would do that though as you'd end up with exponentially growing callbacks.
Agree. Anyway, a valid use case is described here #921 (comment) |
the only use for constraints is to constrain an event. (listen_state or listen_event) |
Whatever dude. |
i guess you dont care if AD keeps running. i think its quite normal to test at least the normal usecase for a function.
|
I'm using the fix for a couple weeks already. I sent a link to my repo above https://github.com/Mithras/ha/blob/tmp/appdaemon/apps/globals.py#L49-L57 |
hmm, perhaps i understand things wrong. i asked: does it work with listen_state? sorry if im confused, but i dont get your first or second answer, because they contradict. your test show an applevel constrain, but custom constraints are mostly used on callback level. |
My first thought was that you are asking if it would work if I await listen_state instead of sleep because immediately after you were talking about how sleep is useless. So my answer was about doing listen_state inside constraint.
I showed how to test it. I did run_in which will make AD execute callback. That exact same as listen_state will. Anyway, it'll work for anything for what sync constraints work today: run_in, listen_state, listen_event, etc. I don't think source of callbacks makes any difference in how constraints work. |
miscommunication ;) i didnt say sleep is useless, but i did say sleep is useless in a constraint. ;)
but only on applevel( if you add the constrain to the app yaml, the whole app is constraint). the common way is on event level like: self.register_constraint("test") thats why i asked. sorry for the miscommunication. |
No worries.
Yes, it works in this case as well |
Will like to merge this, but can we agree on a like better naming for the new util function instead of just Seems a bit rushed. Thanks |
@Odianosen25 Sure, I have no issues renaming it. Do you have a better idea for the name? |
Honestly I don’t, if I had I would have suggested it already. Maybe something in the likes of “run_async_sync_func” or something fancier. I am out of my depths here |
I think we should go with either Regards |
Can you make the changes pls so I can merge this? Or no more interested in it? I want this to be part of the merges I make this weekend. thanks |
@Odianosen25 Just rename |
This fix allows using async constraints.
Example: