Home Assistant Unofficial Reference 2024.12.1
homeassistant.core.EventBus Class Reference

Public Member Functions

None __init__ (self, HomeAssistant hass)
 
None async_fire (self, EventType[_DataT]|str event_type, _DataT|None event_data=None, EventOrigin origin=EventOrigin.local, Context|None context=None, float|None time_fired=None)
 
None async_fire_internal (self, EventType[_DataT]|str event_type, _DataT|None event_data=None, EventOrigin origin=EventOrigin.local, Context|None context=None, float|None time_fired=None)
 
CALLBACK_TYPE async_listen (self, EventType[_DataT]|str event_type, Callable[[Event[_DataT]], Coroutine[Any, Any, None]|None] listener, Callable[[_DataT], bool]|None event_filter=None, bool|object run_immediately=_SENTINEL)
 
CALLBACK_TYPE async_listen_once (self, EventType[_DataT]|str event_type, Callable[[Event[_DataT]], Coroutine[Any, Any, None]|None] listener, bool|object run_immediately=_SENTINEL)
 
dict[EventType[Any]|str, int] async_listeners (self)
 
None fire (self, EventType[_DataT]|str event_type, _DataT|None event_data=None, EventOrigin origin=EventOrigin.local, Context|None context=None)
 
CALLBACK_TYPE listen (self, EventType[_DataT]|str event_type, Callable[[Event[_DataT]], Coroutine[Any, Any, None]|None] listener)
 
CALLBACK_TYPE listen_once (self, EventType[_DataT]|str event_type, Callable[[Event[_DataT]], Coroutine[Any, Any, None]|None] listener)
 
dict[EventType[Any]|str, int] listeners (self)
 

Private Member Functions

CALLBACK_TYPE _async_listen_filterable_job (self, EventType[_DataT]|str event_type, _FilterableJobType[_DataT] filterable_job)
 
None _async_logging_changed (self, Event|None event=None)
 
None _async_remove_listener (self, EventType[_DataT]|str event_type, _FilterableJobType[_DataT] filterable_job)
 

Private Attributes

 _debug
 
 _hass
 

Static Private Attributes

 __slots__
 

Detailed Description

Allow the firing of and listening for events.

Definition at line 1469 of file core.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.core.EventBus.__init__ (   self,
HomeAssistant  hass 
)
Initialize a new event bus.

Definition at line 1474 of file core.py.

Member Function Documentation

◆ _async_listen_filterable_job()

CALLBACK_TYPE homeassistant.core.EventBus._async_listen_filterable_job (   self,
EventType[_DataT] | str  event_type,
_FilterableJobType[_DataT filterable_job 
)
private
Listen for all events or events of a specific type.

Definition at line 1655 of file core.py.

◆ _async_logging_changed()

None homeassistant.core.EventBus._async_logging_changed (   self,
Event | None   event = None 
)
private
Handle logging change.

Definition at line 1486 of file core.py.

◆ _async_remove_listener()

None homeassistant.core.EventBus._async_remove_listener (   self,
EventType[_DataT] | str  event_type,
_FilterableJobType[_DataT filterable_job 
)
private
Remove a listener of a specific event_type.

This method must be run in the event loop.

Definition at line 1732 of file core.py.

◆ async_fire()

None homeassistant.core.EventBus.async_fire (   self,
EventType[_DataT] | str  event_type,
_DataT | None   event_data = None,
EventOrigin   origin = EventOrigin.local,
Context | None   context = None,
float | None   time_fired = None 
)
Fire an event.

This method must be run in the event loop.

Definition at line 1517 of file core.py.

◆ async_fire_internal()

None homeassistant.core.EventBus.async_fire_internal (   self,
EventType[_DataT] | str  event_type,
_DataT | None   event_data = None,
EventOrigin   origin = EventOrigin.local,
Context | None   context = None,
float | None   time_fired = None 
)
Fire an event, for internal use only.

This method is intended to only be used by core internally
and should not be considered a stable API. We will make
breaking changes to this function in the future and it
should not be used in integrations.

This method must be run in the event loop.

Definition at line 1539 of file core.py.

◆ async_listen()

CALLBACK_TYPE homeassistant.core.EventBus.async_listen (   self,
EventType[_DataT] | str  event_type,
Callable[[Event[_DataT]], Coroutine[Any, Any, None] | None]  listener,
Callable[[_DataT], bool] | None   event_filter = None,
bool | object   run_immediately = _SENTINEL 
)
Listen for all events or events of a specific type.

To listen to all events specify the constant ``MATCH_ALL``
as event_type.

An optional event_filter, which must be a callable decorated with
@callback that returns a boolean value, determines if the
listener callable should run.

If run_immediately is passed:
  - callbacks will be run right away instead of using call_soon.
  - coroutine functions will be scheduled eagerly.

This method must be run in the event loop.

Definition at line 1612 of file core.py.

◆ async_listen_once()

CALLBACK_TYPE homeassistant.core.EventBus.async_listen_once (   self,
EventType[_DataT] | str  event_type,
Callable[[Event[_DataT]], Coroutine[Any, Any, None] | None]  listener,
bool | object   run_immediately = _SENTINEL 
)
Listen once for event of a specific type.

To listen to all events specify the constant ``MATCH_ALL``
as event_type.

Returns registered listener that can be used with remove_listener.

This method must be run in the event loop.

Definition at line 1689 of file core.py.

◆ async_listeners()

dict[EventType[Any] | str, int] homeassistant.core.EventBus.async_listeners (   self)
Return dictionary with events and the number of listeners.

This method must be run in the event loop.

Definition at line 1491 of file core.py.

◆ fire()

None homeassistant.core.EventBus.fire (   self,
EventType[_DataT] | str  event_type,
_DataT | None   event_data = None,
EventOrigin   origin = EventOrigin.local,
Context | None   context = None 
)
Fire an event.

Definition at line 1503 of file core.py.

◆ listen()

CALLBACK_TYPE homeassistant.core.EventBus.listen (   self,
EventType[_DataT] | str  event_type,
Callable[[Event[_DataT]], Coroutine[Any, Any, None] | None]  listener 
)
Listen for all events or events of a specific type.

To listen to all events specify the constant ``MATCH_ALL``
as event_type.

Definition at line 1591 of file core.py.

◆ listen_once()

CALLBACK_TYPE homeassistant.core.EventBus.listen_once (   self,
EventType[_DataT] | str  event_type,
Callable[[Event[_DataT]], Coroutine[Any, Any, None] | None]  listener 
)
Listen once for event of a specific type.

To listen to all events specify the constant ``MATCH_ALL``
as event_type.

Returns function to unsubscribe the listener.

Definition at line 1666 of file core.py.

◆ listeners()

dict[EventType[Any] | str, int] homeassistant.core.EventBus.listeners (   self)
Return dictionary with events and the number of listeners.

Definition at line 1499 of file core.py.

Member Data Documentation

◆ __slots__

homeassistant.core.EventBus.__slots__
staticprivate

Definition at line 1472 of file core.py.

◆ _debug

homeassistant.core.EventBus._debug
private

Definition at line 1488 of file core.py.

◆ _hass

homeassistant.core.EventBus._hass
private

Definition at line 1481 of file core.py.


The documentation for this class was generated from the following file: