Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.websocket_api.decorators Namespace Reference

Functions

None _handle_async_response (const .AsyncWebSocketCommandHandler func, HomeAssistant hass, ActiveConnection connection, dict[str, Any] msg)
 
const .WebSocketCommandHandler async_response (const .AsyncWebSocketCommandHandler func)
 
const .WebSocketCommandHandler require_admin (const .WebSocketCommandHandler func)
 
Callable[[const .WebSocketCommandHandler], const .WebSocketCommandHandler] websocket_command (VolDictType|vol.All schema)
 
Callable[[const .WebSocketCommandHandler], const .WebSocketCommandHandler] ws_require_user (bool only_owner=False, bool only_system_user=False, bool allow_system_user=True, bool only_active_user=True, bool only_inactive_user=False, bool only_supervisor=False)
 

Detailed Description

Decorators for the Websocket API.

Function Documentation

◆ _handle_async_response()

None homeassistant.components.websocket_api.decorators._handle_async_response ( const.AsyncWebSocketCommandHandler  func,
HomeAssistant  hass,
ActiveConnection  connection,
dict[str, Any]  msg 
)
private
Create a response and handle exception.

Definition at line 20 of file decorators.py.

◆ async_response()

const.WebSocketCommandHandler homeassistant.components.websocket_api.decorators.async_response ( const.AsyncWebSocketCommandHandler  func)
Decorate an async function to handle WebSocket API messages.

Definition at line 33 of file decorators.py.

◆ require_admin()

const.WebSocketCommandHandler homeassistant.components.websocket_api.decorators.require_admin ( const.WebSocketCommandHandler  func)
Websocket decorator to require user to be an admin.

Definition at line 56 of file decorators.py.

◆ websocket_command()

Callable[[const.WebSocketCommandHandler], const.WebSocketCommandHandler] homeassistant.components.websocket_api.decorators.websocket_command ( VolDictType | vol.All  schema)
Tag a function as a websocket command.

The schema must be either a dictionary where the keys are voluptuous markers, or
a voluptuous.All schema where the first item is a voluptuous Mapping schema.

Definition at line 133 of file decorators.py.

◆ ws_require_user()

Callable[[const.WebSocketCommandHandler], const.WebSocketCommandHandler] homeassistant.components.websocket_api.decorators.ws_require_user ( bool   only_owner = False,
bool   only_system_user = False,
bool   allow_system_user = True,
bool   only_active_user = True,
bool   only_inactive_user = False,
bool   only_supervisor = False 
)
Decorate function validating login user exist in current WS connection.

Will write out error message if not authenticated.

Definition at line 74 of file decorators.py.