Module homey.util.event_emitter
Classes
class EventEmitter-
Abstract base class for generic types.
On Python 3.12 and newer, generic classes implicitly inherit from Generic when they declare a parameter list after the class's name::
class Mapping[KT, VT]: def __getitem__(self, key: KT) -> VT: ... # Etc.On older versions of Python, however, generic classes have to explicitly inherit from Generic.
After a class has been declared to be generic, it can then be used as follows::
def lookup_name[KT, VT](mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return defaultAncestors
- typing.Generic
Subclasses
- Api
- homey.client.socket.Socket
- SimpleClass
Methods
def on(self, event: Event, f: Callable[..., None]) ‑> Self-
Register the function
fto the event nameevent:def data_handler(data): print(data) handler = ee.on("event", data_handler) def once(self, event: Event, f: Callable[..., None]) ‑> Self-
Register the function
fto the event nameevent. The listener is automatically removed after being called. def emit(self, event: Event, *args: Any, **kwargs: Any) ‑> bool-
Emit
event, passing*argsand**kwargsto each attached function. ReturnsTrueif any functions are attached toevent; otherwise returnsFalse.Example:
ee.emit('data', '00101001')Assuming
on_datais an attached function, this will callon_data('00101001')'. def remove_listener(self, event: Event, f: Callable[..., None]) ‑> Self-
Unregister the function
ffrom the event nameevent: def remove_all_listeners(self, event: Event | None = None) ‑> Self-
Remove all listeners attached to
event. IfeventisNone, remove all listeners on all events. def event_names(self) ‑> Set[~Event]-
Get a set of events that this emitter is listening to.
class EventException (*args, **kwargs)-
An uncaught error event.
Ancestors
- builtins.Exception
- builtins.BaseException