2018-10-01 09:21:00 +00:00
|
|
|
"""Websocket constants."""
|
2018-10-01 14:09:31 +00:00
|
|
|
import asyncio
|
|
|
|
from concurrent import futures
|
2019-05-14 03:57:47 +00:00
|
|
|
from functools import partial
|
|
|
|
import json
|
|
|
|
from homeassistant.helpers.json import JSONEncoder
|
2018-10-01 14:09:31 +00:00
|
|
|
|
|
|
|
DOMAIN = 'websocket_api'
|
|
|
|
URL = '/api/websocket'
|
|
|
|
MAX_PENDING_MSG = 512
|
|
|
|
|
2018-11-27 09:12:31 +00:00
|
|
|
ERR_ID_REUSE = 'id_reuse'
|
|
|
|
ERR_INVALID_FORMAT = 'invalid_format'
|
|
|
|
ERR_NOT_FOUND = 'not_found'
|
2019-03-02 07:09:31 +00:00
|
|
|
ERR_HOME_ASSISTANT_ERROR = 'home_assistant_error'
|
2018-11-27 09:12:31 +00:00
|
|
|
ERR_UNKNOWN_COMMAND = 'unknown_command'
|
|
|
|
ERR_UNKNOWN_ERROR = 'unknown_error'
|
|
|
|
ERR_UNAUTHORIZED = 'unauthorized'
|
2018-10-01 09:21:00 +00:00
|
|
|
|
|
|
|
TYPE_RESULT = 'result'
|
2018-10-01 14:09:31 +00:00
|
|
|
|
|
|
|
# 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)
|
2019-03-22 18:59:10 +00:00
|
|
|
|
|
|
|
# Event types
|
|
|
|
SIGNAL_WEBSOCKET_CONNECTED = 'websocket_connected'
|
|
|
|
SIGNAL_WEBSOCKET_DISCONNECTED = 'websocket_disconnected'
|
2019-04-13 17:48:40 +00:00
|
|
|
|
|
|
|
# Data used to store the current connection list
|
|
|
|
DATA_CONNECTIONS = DOMAIN + '.connections'
|
2019-05-14 03:57:47 +00:00
|
|
|
|
|
|
|
JSON_DUMP = partial(json.dumps, cls=JSONEncoder, allow_nan=False)
|