Skip to content

Commit

Permalink
Return callback to unsubscribe to entity (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored May 8, 2024
1 parent 8b63996 commit 7f368b9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pylutron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 7f368b9

Please sign in to comment.