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

Public Member Functions

None __init__ (self, HomeAssistant hass)
 
ServiceResponse async_call (self, str domain, str service, dict[str, Any]|None service_data=None, bool blocking=False, Context|None context=None, dict[str, Any]|None target=None, bool return_response=False)
 
None async_register (self, str domain, str service, Callable[[ServiceCall], Coroutine[Any, Any, ServiceResponse|EntityServiceResponse]|ServiceResponse|EntityServiceResponse|None,] service_func, VolSchemaType|None schema=None, SupportsResponse supports_response=SupportsResponse.NONE, HassJobType|None job_type=None)
 
None async_remove (self, str domain, str service)
 
dict[str, dict[str, Service]] async_services (self)
 
dict[str, Serviceasync_services_for_domain (self, str domain)
 
dict[str, dict[str, Service]] async_services_internal (self)
 
ServiceResponse call (self, str domain, str service, dict[str, Any]|None service_data=None, bool blocking=False, Context|None context=None, dict[str, Any]|None target=None, bool return_response=False)
 
bool has_service (self, str domain, str service)
 
None register (self, str domain, str service, Callable[[ServiceCall], Coroutine[Any, Any, ServiceResponse]|ServiceResponse|None,] service_func, vol.Schema|None schema=None, SupportsResponse supports_response=SupportsResponse.NONE)
 
None remove (self, str domain, str service)
 
dict[str, dict[str, Service]] services (self)
 
SupportsResponse supports_response (self, str domain, str service)
 

Private Member Functions

None _async_register (self, str domain, str service, Callable[[ServiceCall], Coroutine[Any, Any, ServiceResponse|EntityServiceResponse]|ServiceResponse|EntityServiceResponse|None,] service_func, VolSchemaType|None schema=None, SupportsResponse supports_response=SupportsResponse.NONE, HassJobType|None job_type=None)
 
None _async_remove (self, str domain, str service)
 
ServiceResponse _execute_service (self, Service handler, ServiceCall service_call)
 
None _run_service_call_catch_exceptions (self, Coroutine[Any, Any, Any]|asyncio.Task[Any] coro_or_task, ServiceCall service_call)
 

Private Attributes

 _hass
 

Static Private Attributes

 __slots__
 

Detailed Description

Offer the services over the eventbus.

Definition at line 2472 of file core.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.core.ServiceRegistry.__init__ (   self,
HomeAssistant  hass 
)
Initialize a service registry.

Definition at line 2477 of file core.py.

Member Function Documentation

◆ _async_register()

None homeassistant.core.ServiceRegistry._async_register (   self,
str  domain,
str  service,
Callable[ [ServiceCall], Coroutine[Any, Any, ServiceResponse | EntityServiceResponse] | ServiceResponse | EntityServiceResponse | None, ]  service_func,
VolSchemaType | None   schema = None,
SupportsResponse   supports_response = SupportsResponse.NONE,
HassJobType | None   job_type = None 
)
private
Register a service.

Schema is called to coerce and validate the service data.

This method must be run in the event loop.

Definition at line 2592 of file core.py.

◆ _async_remove()

None homeassistant.core.ServiceRegistry._async_remove (   self,
str  domain,
str  service 
)
private
Remove a registered service from service handler.

This method must be run in the event loop.

Definition at line 2649 of file core.py.

◆ _execute_service()

ServiceResponse homeassistant.core.ServiceRegistry._execute_service (   self,
Service  handler,
ServiceCall   service_call 
)
private
Execute a service.

Definition at line 2834 of file core.py.

◆ _run_service_call_catch_exceptions()

None homeassistant.core.ServiceRegistry._run_service_call_catch_exceptions (   self,
Coroutine[Any, Any, Any] | asyncio.Task[Any]  coro_or_task,
ServiceCall  service_call 
)
private
Run service call in background, catching and logging any exceptions.

Definition at line 2815 of file core.py.

◆ async_call()

ServiceResponse homeassistant.core.ServiceRegistry.async_call (   self,
str  domain,
str  service,
dict[str, Any] | None   service_data = None,
bool   blocking = False,
Context | None   context = None,
dict[str, Any] | None   target = None,
bool   return_response = False 
)
Call a service.

Specify blocking=True to wait until service is executed.

If return_response=True, indicates that the caller can consume return values
from the service, if any. Return values are a dict that can be returned by the
standard JSON serialization process. Return values can only be used with blocking=True.

This method will fire an event to indicate the service has been called.

Because the service is sent as an event you are not allowed to use
the keys ATTR_DOMAIN and ATTR_SERVICE in your service_data.

This method is a coroutine.

Definition at line 2697 of file core.py.

◆ async_register()

None homeassistant.core.ServiceRegistry.async_register (   self,
str  domain,
str  service,
Callable[ [ServiceCall], Coroutine[Any, Any, ServiceResponse | EntityServiceResponse] | ServiceResponse | EntityServiceResponse | None, ]  service_func,
VolSchemaType | None   schema = None,
SupportsResponse   supports_response = SupportsResponse.NONE,
HassJobType | None   job_type = None 
)
Register a service.

Schema is called to coerce and validate the service data.

This method must be run in the event loop.

Definition at line 2565 of file core.py.

◆ async_remove()

None homeassistant.core.ServiceRegistry.async_remove (   self,
str  domain,
str  service 
)
Remove a registered service from service handler.

This method must be run in the event loop.

Definition at line 2640 of file core.py.

◆ async_services()

dict[str, dict[str, Service]] homeassistant.core.ServiceRegistry.async_services (   self)
Return dictionary with per domain a list of available services.

This method makes a copy of the registry. This function is expensive,
and should only be used if has_service is not sufficient.

This method must be run in the event loop.

Definition at line 2488 of file core.py.

◆ async_services_for_domain()

dict[str, Service] homeassistant.core.ServiceRegistry.async_services_for_domain (   self,
str  domain 
)
Return dictionary with per domain a list of available services.

This method makes a copy of the registry for the domain.

This method must be run in the event loop.

Definition at line 2499 of file core.py.

◆ async_services_internal()

dict[str, dict[str, Service]] homeassistant.core.ServiceRegistry.async_services_internal (   self)
Return dictionary with per domain a list of available services.

This method DOES NOT make a copy of the services like async_services does.
It is only expected to be called from the Home Assistant internals
as a performance optimization when the caller is not going to modify the
returned data.

This method must be run in the event loop.

Definition at line 2509 of file core.py.

◆ call()

ServiceResponse homeassistant.core.ServiceRegistry.call (   self,
str  domain,
str  service,
dict[str, Any] | None   service_data = None,
bool   blocking = False,
Context | None   context = None,
dict[str, Any] | None   target = None,
bool   return_response = False 
)
Call a service.

See description of async_call for details.

Definition at line 2670 of file core.py.

◆ has_service()

bool homeassistant.core.ServiceRegistry.has_service (   self,
str  domain,
str  service 
)
Test if specified service exists.

Async friendly.

Definition at line 2521 of file core.py.

◆ register()

None homeassistant.core.ServiceRegistry.register (   self,
str  domain,
str  service,
Callable[ [ServiceCall], Coroutine[Any, Any, ServiceResponse] | ServiceResponse | None, ]  service_func,
vol.Schema | None   schema = None,
SupportsResponse   supports_response = SupportsResponse.NONE 
)
Register a service.

Schema is called to coerce and validate the service data.

Definition at line 2539 of file core.py.

◆ remove()

None homeassistant.core.ServiceRegistry.remove (   self,
str  domain,
str  service 
)
Remove a registered service from service handler.

Definition at line 2633 of file core.py.

◆ services()

dict[str, dict[str, Service]] homeassistant.core.ServiceRegistry.services (   self)
Return dictionary with per domain a list of available services.

Definition at line 2483 of file core.py.

◆ supports_response()

SupportsResponse homeassistant.core.ServiceRegistry.supports_response (   self,
str  domain,
str  service 
)
Return whether or not the service supports response data.

This exists so that callers can return more helpful error messages given
the context. Will return NONE if the service does not exist as there is
other error handling when calling the service if it does not exist.

Definition at line 2528 of file core.py.

Member Data Documentation

◆ __slots__

homeassistant.core.ServiceRegistry.__slots__
staticprivate

Definition at line 2475 of file core.py.

◆ _hass

homeassistant.core.ServiceRegistry._hass
private

Definition at line 2480 of file core.py.


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