2018-10-01 11:21:00 +02:00
|
|
|
"""Websocket constants."""
|
2024-03-08 16:35:45 +01:00
|
|
|
|
2021-05-21 17:39:18 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2022-01-12 09:04:37 +01:00
|
|
|
from collections.abc import Awaitable, Callable
|
|
|
|
|
from typing import TYPE_CHECKING, Any, Final
|
2019-12-08 12:19:15 +01:00
|
|
|
|
2020-01-03 21:37:11 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
2018-10-01 16:09:31 +02:00
|
|
|
|
2020-01-03 21:37:11 +01:00
|
|
|
if TYPE_CHECKING:
|
2024-03-16 20:48:37 +01:00
|
|
|
from .connection import ActiveConnection
|
2020-01-03 21:37:11 +01:00
|
|
|
|
|
|
|
|
|
2024-05-17 14:42:21 +02:00
|
|
|
type WebSocketCommandHandler = Callable[
|
|
|
|
|
[HomeAssistant, ActiveConnection, dict[str, Any]], None
|
2021-05-21 17:39:18 +01:00
|
|
|
]
|
2024-05-17 14:42:21 +02:00
|
|
|
type AsyncWebSocketCommandHandler = Callable[
|
|
|
|
|
[HomeAssistant, ActiveConnection, dict[str, Any]], Awaitable[None]
|
2021-05-21 17:39:18 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
DOMAIN: Final = "websocket_api"
|
|
|
|
|
URL: Final = "/api/websocket"
|
2023-01-29 10:49:27 -10:00
|
|
|
PENDING_MSG_PEAK: Final = 1024
|
2025-03-28 09:32:00 -10:00
|
|
|
PENDING_MSG_PEAK_TIME: Final = 10
|
2023-01-29 10:49:27 -10:00
|
|
|
# Maximum number of messages that can be pending at any given time.
|
|
|
|
|
# This is effectively the upper limit of the number of entities
|
|
|
|
|
# that can fire state changes within ~1 second.
|
2024-05-28 17:14:06 -10:00
|
|
|
# Ideally we would use homeassistant.const.MAX_EXPECTED_ENTITY_IDS
|
|
|
|
|
# but since chrome will lock up with too many messages we need to
|
|
|
|
|
# limit it to a lower number.
|
2023-01-29 10:49:27 -10:00
|
|
|
MAX_PENDING_MSG: Final = 4096
|
2021-05-21 17:39:18 +01:00
|
|
|
|
2024-05-28 17:14:06 -10:00
|
|
|
# Maximum number of messages that are pending before we force
|
|
|
|
|
# resolve the ready future.
|
|
|
|
|
PENDING_MSG_MAX_FORCE_READY: Final = 256
|
|
|
|
|
|
2021-05-21 17:39:18 +01:00
|
|
|
ERR_ID_REUSE: Final = "id_reuse"
|
|
|
|
|
ERR_INVALID_FORMAT: Final = "invalid_format"
|
2023-02-15 18:55:10 +01:00
|
|
|
ERR_NOT_ALLOWED: Final = "not_allowed"
|
2021-05-21 17:39:18 +01:00
|
|
|
ERR_NOT_FOUND: Final = "not_found"
|
|
|
|
|
ERR_NOT_SUPPORTED: Final = "not_supported"
|
|
|
|
|
ERR_HOME_ASSISTANT_ERROR: Final = "home_assistant_error"
|
2023-11-06 15:45:04 +01:00
|
|
|
ERR_SERVICE_VALIDATION_ERROR: Final = "service_validation_error"
|
2021-05-21 17:39:18 +01:00
|
|
|
ERR_UNKNOWN_COMMAND: Final = "unknown_command"
|
|
|
|
|
ERR_UNKNOWN_ERROR: Final = "unknown_error"
|
|
|
|
|
ERR_UNAUTHORIZED: Final = "unauthorized"
|
|
|
|
|
ERR_TIMEOUT: Final = "timeout"
|
|
|
|
|
ERR_TEMPLATE_ERROR: Final = "template_error"
|
|
|
|
|
|
|
|
|
|
TYPE_RESULT: Final = "result"
|
2018-10-01 16:09:31 +02:00
|
|
|
|
2019-03-23 02:59:10 +08:00
|
|
|
|
|
|
|
|
# Event types
|
2021-05-21 17:39:18 +01:00
|
|
|
SIGNAL_WEBSOCKET_CONNECTED: Final = "websocket_connected"
|
|
|
|
|
SIGNAL_WEBSOCKET_DISCONNECTED: Final = "websocket_disconnected"
|
2019-04-14 01:48:40 +08:00
|
|
|
|
|
|
|
|
# Data used to store the current connection list
|
2021-05-21 17:39:18 +01:00
|
|
|
DATA_CONNECTIONS: Final = f"{DOMAIN}.connections"
|
2019-05-14 05:57:47 +02:00
|
|
|
|
2022-08-24 22:50:48 -05:00
|
|
|
FEATURE_COALESCE_MESSAGES = "coalesce_messages"
|