Add missing type hints to websocket_api (#50915)
This commit is contained in:
parent
dc65f279a7
commit
42ff687c32
11 changed files with 251 additions and 159 deletions
|
@ -1,9 +1,11 @@
|
|||
"""Websocket constants."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from concurrent import futures
|
||||
from functools import partial
|
||||
import json
|
||||
from typing import TYPE_CHECKING, Callable
|
||||
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Final
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.json import JSONEncoder
|
||||
|
@ -12,37 +14,42 @@ if TYPE_CHECKING:
|
|||
from .connection import ActiveConnection
|
||||
|
||||
|
||||
WebSocketCommandHandler = Callable[[HomeAssistant, "ActiveConnection", dict], None]
|
||||
WebSocketCommandHandler = Callable[
|
||||
[HomeAssistant, "ActiveConnection", Dict[str, Any]], None
|
||||
]
|
||||
AsyncWebSocketCommandHandler = Callable[
|
||||
[HomeAssistant, "ActiveConnection", Dict[str, Any]], Awaitable[None]
|
||||
]
|
||||
|
||||
DOMAIN = "websocket_api"
|
||||
URL = "/api/websocket"
|
||||
PENDING_MSG_PEAK = 512
|
||||
PENDING_MSG_PEAK_TIME = 5
|
||||
MAX_PENDING_MSG = 2048
|
||||
DOMAIN: Final = "websocket_api"
|
||||
URL: Final = "/api/websocket"
|
||||
PENDING_MSG_PEAK: Final = 512
|
||||
PENDING_MSG_PEAK_TIME: Final = 5
|
||||
MAX_PENDING_MSG: Final = 2048
|
||||
|
||||
ERR_ID_REUSE = "id_reuse"
|
||||
ERR_INVALID_FORMAT = "invalid_format"
|
||||
ERR_NOT_FOUND = "not_found"
|
||||
ERR_NOT_SUPPORTED = "not_supported"
|
||||
ERR_HOME_ASSISTANT_ERROR = "home_assistant_error"
|
||||
ERR_UNKNOWN_COMMAND = "unknown_command"
|
||||
ERR_UNKNOWN_ERROR = "unknown_error"
|
||||
ERR_UNAUTHORIZED = "unauthorized"
|
||||
ERR_TIMEOUT = "timeout"
|
||||
ERR_TEMPLATE_ERROR = "template_error"
|
||||
ERR_ID_REUSE: Final = "id_reuse"
|
||||
ERR_INVALID_FORMAT: Final = "invalid_format"
|
||||
ERR_NOT_FOUND: Final = "not_found"
|
||||
ERR_NOT_SUPPORTED: Final = "not_supported"
|
||||
ERR_HOME_ASSISTANT_ERROR: Final = "home_assistant_error"
|
||||
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 = "result"
|
||||
TYPE_RESULT: Final = "result"
|
||||
|
||||
# Define the possible errors that occur when connections are cancelled.
|
||||
# Originally, this was just asyncio.CancelledError, but issue #9546 showed
|
||||
# that futures.CancelledErrors can also occur in some situations.
|
||||
CANCELLATION_ERRORS = (asyncio.CancelledError, futures.CancelledError)
|
||||
CANCELLATION_ERRORS: Final = (asyncio.CancelledError, futures.CancelledError)
|
||||
|
||||
# Event types
|
||||
SIGNAL_WEBSOCKET_CONNECTED = "websocket_connected"
|
||||
SIGNAL_WEBSOCKET_DISCONNECTED = "websocket_disconnected"
|
||||
SIGNAL_WEBSOCKET_CONNECTED: Final = "websocket_connected"
|
||||
SIGNAL_WEBSOCKET_DISCONNECTED: Final = "websocket_disconnected"
|
||||
|
||||
# Data used to store the current connection list
|
||||
DATA_CONNECTIONS = f"{DOMAIN}.connections"
|
||||
DATA_CONNECTIONS: Final = f"{DOMAIN}.connections"
|
||||
|
||||
JSON_DUMP = partial(json.dumps, cls=JSONEncoder, allow_nan=False)
|
||||
JSON_DUMP: Final = partial(json.dumps, cls=JSONEncoder, allow_nan=False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue