ryqiem
(Martin Bernstorff)
April 12, 2017, 9:06am
1
Hi guys!
I was trying to run a Scheduler Callback with this basic structure:
class myClass(appapi.AppDaemon):
def initialize(self):
self.run_in(self.function(), 10)
def function(self, *args, **kwargs):
<work work>
and got no delay. However, if I remove the () from the callback like this:
class myClass(appapi.AppDaemon):
def initialize(self):
self.run_in(self.function, 10)
def function(self, *args, **kwargs):
<work work>
it works just fine. Took me quite some time to figure out, maybe it’s a good idea to post an error in this case?
gpbenton
(Graham)
April 12, 2017, 2:24pm
2
When you have self.function()
, your code is calling the function at that point, which is why there is no delay. This is perfectly valid Python, so no error can be generated, even if it is not what you wanted.
Incidentally, your callback should match the declaration in this paragraph
https://github.com/home-assistant/appdaemon/blob/master/API.md#about-schedule-callbacks
although if you don’t use the kwargs, it probably won’t make any difference.
1 Like
ryqiem
(Martin Bernstorff)
April 13, 2017, 11:50am
3
Didn’t realise you could call a function within another function’s arguments
Thanks for clearing it up!