Intended behaviour of Scheduler Callback

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? :slight_smile:

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

Didn’t realise you could call a function within another function’s arguments :blush:

Thanks for clearing it up!