Home Assistant Unofficial Reference 2024.12.1
const.py
Go to the documentation of this file.
1 """Websocket constants."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Awaitable, Callable
6 from typing import TYPE_CHECKING, Any, Final
7 
8 from homeassistant.core import HomeAssistant
9 
10 if TYPE_CHECKING:
11  from .connection import ActiveConnection
12 
13 
14 type WebSocketCommandHandler = Callable[
15  [HomeAssistant, ActiveConnection, dict[str, Any]], None
16 ]
17 type AsyncWebSocketCommandHandler = Callable[
18  [HomeAssistant, ActiveConnection, dict[str, Any]], Awaitable[None]
19 ]
20 
21 DOMAIN: Final = "websocket_api"
22 URL: Final = "/api/websocket"
23 PENDING_MSG_PEAK: Final = 1024
24 PENDING_MSG_PEAK_TIME: Final = 5
25 # Maximum number of messages that can be pending at any given time.
26 # This is effectively the upper limit of the number of entities
27 # that can fire state changes within ~1 second.
28 # Ideally we would use homeassistant.const.MAX_EXPECTED_ENTITY_IDS
29 # but since chrome will lock up with too many messages we need to
30 # limit it to a lower number.
31 MAX_PENDING_MSG: Final = 4096
32 
33 # Maximum number of messages that are pending before we force
34 # resolve the ready future.
35 PENDING_MSG_MAX_FORCE_READY: Final = 256
36 
37 ERR_ID_REUSE: Final = "id_reuse"
38 ERR_INVALID_FORMAT: Final = "invalid_format"
39 ERR_NOT_ALLOWED: Final = "not_allowed"
40 ERR_NOT_FOUND: Final = "not_found"
41 ERR_NOT_SUPPORTED: Final = "not_supported"
42 ERR_HOME_ASSISTANT_ERROR: Final = "home_assistant_error"
43 ERR_SERVICE_VALIDATION_ERROR: Final = "service_validation_error"
44 ERR_UNKNOWN_COMMAND: Final = "unknown_command"
45 ERR_UNKNOWN_ERROR: Final = "unknown_error"
46 ERR_UNAUTHORIZED: Final = "unauthorized"
47 ERR_TIMEOUT: Final = "timeout"
48 ERR_TEMPLATE_ERROR: Final = "template_error"
49 
50 TYPE_RESULT: Final = "result"
51 
52 
53 # Event types
54 SIGNAL_WEBSOCKET_CONNECTED: Final = "websocket_connected"
55 SIGNAL_WEBSOCKET_DISCONNECTED: Final = "websocket_disconnected"
56 
57 # Data used to store the current connection list
58 DATA_CONNECTIONS: Final = f"{DOMAIN}.connections"
59 
60 FEATURE_COALESCE_MESSAGES = "coalesce_messages"