-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from s-kostyuk/thing_events
Thing on_update events This pull request prepares infrastructure for tracking of updates of Things and their properties - added a protected method called `_apply_update()` for notification of subscribers on Thing updates; - added a new interface (abstract class) called UpdateCallback which allows to assign callbacks to be called on each update of an object (i.e. Thing); - implemented UpdateCallback interface for a base Thing implementation; - added `_apply_update()` calls for base Actuator implementation Closes #12
- Loading branch information
Showing
3 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Optional, Callable | ||
|
||
|
||
class UpdateCallback(object): | ||
""" | ||
Implementations of UpdateCallback interface has an on_update property | ||
that allows to define a single callback to be called on each update | ||
of a Thing. | ||
A callback to be registered must to accept a single parameter: a weak | ||
reference to the event source (i.e. to the updated Thing) | ||
""" | ||
@property | ||
def on_update(self) -> Optional[Callable]: | ||
""" | ||
Returns a callable that is currently registered to be called on each | ||
update of this object | ||
:return: a callable that is currently registered to be called on each | ||
update of this object; or None if a callable wasn't set yet | ||
""" | ||
raise NotImplementedError() | ||
|
||
@on_update.setter | ||
def on_update(self, callback: Optional[Callable]) -> None: | ||
""" | ||
Allows to set a callable to be called on each update of this object. | ||
This callable must to accept a reference to the event source (i.e. to | ||
this object) | ||
:param callback: a new callback to be set or None to unset a callback | ||
:return: None | ||
""" | ||
raise NotImplementedError() |