Cancel a timer created in a different app?

It appears that self.cancel_timer() will only cancel timers created within that app: if App A creates a timer and saves the handle to App B, App B’s use of self.cancel_timer on that handle doesn’t do anything.

Is this possible (or, if not, would it be easy to add)? I’m wanting to have a handler registry app that manages timer handles on behalf of all apps so as to give multi-point ability to adjust them (example: if the dishwasher app sets a recurring notification, I might want the Alexa app to be able to cancel it).

Thanks!

Looking closer at the source, these sections stand out:

In appapi.py:

def cancel_timer(self, handle):
        name = self.name
        self.AD.cancel_timer(name, handle)

…and in appdaemon.py:

def cancel_timer(self, name, handle):
        self.log("DEBUG", "Canceling timer for {}".format(name))
        with self.schedule_lock:
            if name in self.schedule and handle in self.schedule[name]:
                del self.schedule[name][handle]
            if name in self.schedule and self.schedule[name] == {}:
                del self.schedule[name]

Guessing from this that:

  1. Handles, indeed, “exist” only for the app in which they’re created.
  2. The method exposed in appapi.py hardcodes the “app domain” to be the current app.

If this is true, I’m guessing that I could change this:

self.cancel_timer(handle)

…to this:

self.AD.cancel_timer('app_a', handle)

@aimc, at your leisure, could you confirm that my assumption is correct? If so, is my suggestion above correct, or should appapi.py's clear_timer method perhaps be enhanced to allow configuration of the “app domain,” like this:

def cancel_timer(self, handle, name=None):
        if not name:
            name = self.name
        self.AD.cancel_timer(name, handle) 

?

Yes, you are correct in all respects, however using the AD function directly is relying on an unpublished interface that might change at some point.

I have the same requirement in my apps and I simply write a cancel routine in each app and add that function to a global registry, then when I need to I iterate through the registry and call each function.

Ooh, interesting concept. I’ll give that a shot. Thank you!

1 Like