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 default

Ancestors

  • typing.Generic

Subclasses

Methods

def on(self, event: Event, f: Callable[..., None]) ‑> Self

Register the function f to the event name event:

def data_handler(data):
    print(data)

handler = ee.on("event", data_handler)
def once(self, event: Event, f: Callable[..., None]) ‑> Self

Register the function f to the event name event. The listener is automatically removed after being called.

def emit(self, event: Event, *args: Any, **kwargs: Any) ‑> bool

Emit event, passing *args and **kwargs to each attached function. Returns True if any functions are attached to event; otherwise returns False.

Example:

ee.emit('data', '00101001')

Assuming on_data is an attached function, this will call on_data('00101001')'.

def remove_listener(self, event: Event, f: Callable[..., None]) ‑> Self

Unregister the function f from the event name event:

def remove_all_listeners(self, event: Event | None = None) ‑> Self

Remove all listeners attached to event. If event is None, 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