diff --git a/pylutron/__init__.py b/pylutron/__init__.py index 9ffe56c..5ba6cdd 100644 --- a/pylutron/__init__.py +++ b/pylutron/__init__.py @@ -632,7 +632,7 @@ def _dispatch_event(self, event: LutronEvent, params: Dict): for handler, context in self._subscribers: handler(self, context, event, params) - def subscribe(self, handler: LutronEventHandler, context): + def subscribe(self, handler: LutronEventHandler, context) -> Callable[[], None]: """Subscribes to events from this entity. handler: A callable object that takes the following arguments (in order) @@ -642,8 +642,10 @@ def subscribe(self, handler: LutronEventHandler, context): params: a dict of event-specific parameters context: User-supplied, opaque object that will be passed to handler. + Returns: A callable that can be used to unsubscribe from the event. """ self._subscribers.append((handler, context)) + return lambda: self._subscribers.remove((handler, context)) def handle_update(self, args): """The handle_update callback is invoked when an event is received