-
Notifications
You must be signed in to change notification settings - Fork 46
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
Feature request (low): adding a "now" keyword for @time_trigger #139
Comments
I agree this would be useful. At the moment, I use a function like this to make it a bit easier:
And use it like this:
There are some caveats to be aware of, though. PyScript will accept a An easier alternative uses
|
This is also what I was concerned with for When I used |
The So adding
If I made An alternative is to set
Now that I wrote all that, the 2nd option definitely looks the simplest and most intuitive. Thoughts? |
I agree that that 2nd option is more intuitive than the first. I'm not keen on the idea of setting now to "just after the current time at startup" because it means that in a trigger created well after startup "now" no longer means "now" but, really just means some time in the past. I think I would prefer a solution where "once(now)" works like |
Yes, this is exactly what I had in mind. My major issue with the situation today (it is the same in AppDaemon BTW) is that the request is not natural. Nobody is going to say "do it in 10 minutes, and start the countdown now". They will say "do it in 10 minutes" and it is obvious that it starts "now". So If I want to say "do it now", it is If I want to say "do it every 3 hours", I expect The thing is that "now" in pyscript is the same as "startup", which is understandable, but not immediately obvious when building a script. If now needs to be "now + 10 ms because otherwise now will be in the past when we get there" - no problem for me. I definitely prefer that to building a datetime thing (which I will use Having a |
I've implemented it as discussed.
I didn't explain it clearly. Hopefully the docs explain it better. |
excellent! now, a question of garbage collection... I think that, over time, this would run out of memory. But maybe it wouldn't? Obviously, there are easier/better ways to do the below, this is merely a point of curiosity.
|
Yes, that should work, although as you point out it's a lot less efficient than just doing a I tried this alternative to clean up as it goes: RT = set()
@time_trigger('period(now, 3s)')
def every_3sec():
@time_trigger('once(now + 10sec)')
def do_something_10sec_later():
log.info("do_something_10sec_later")
RT.discard(do_something_10sec_later)
RT.add(do_something_10sec_later)
However, this doesn't cancel (delete) each trigger function since the function body now has a reference to itself, so the |
That's an interesting way to go about it. I like it. Though, as mentioned, not critical since there are better ways to accomplish these same tasks. |
In the same vein as to
noon
ormidnight
, it would be great to have anow
entry that would simplify the use of@time_trigger
.A typical case is would be
@time_trigger("period(now, 1m)")
or@time_trigger("period(now+1h, 1m)")
. This would help to avoid fiddling withdatetime
.I had a look at the code (
pyscript/custom_components/pyscript/trigger.py
Line 566 in dcd1748
arrow
(alternatives arependulum
, ordelorean
) because I never could get the time / date right (this is for me one of the most messed up parts in Python)The text was updated successfully, but these errors were encountered: