mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Avoid references to websocket_api.const in core and other components (#119285)
This commit is contained in:
parent
2e3c3789d3
commit
960d1289ef
@ -1648,9 +1648,7 @@ class PipelineStorageCollectionWebsocket(
|
||||
try:
|
||||
await super().ws_delete_item(hass, connection, msg)
|
||||
except PipelinePreferred as exc:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_ALLOWED, str(exc)
|
||||
)
|
||||
connection.send_error(msg["id"], websocket_api.ERR_NOT_ALLOWED, str(exc))
|
||||
|
||||
@callback
|
||||
def ws_get_item(
|
||||
@ -1664,7 +1662,7 @@ class PipelineStorageCollectionWebsocket(
|
||||
if item_id not in self.storage_collection.data:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_FOUND,
|
||||
websocket_api.ERR_NOT_FOUND,
|
||||
f"Unable to find {self.item_id_key} {item_id}",
|
||||
)
|
||||
return
|
||||
@ -1695,7 +1693,7 @@ class PipelineStorageCollectionWebsocket(
|
||||
self.storage_collection.async_set_preferred_item(msg[self.item_id_key])
|
||||
except ItemNotFound:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "unknown item"
|
||||
msg["id"], websocket_api.ERR_NOT_FOUND, "unknown item"
|
||||
)
|
||||
return
|
||||
connection.send_result(msg["id"])
|
||||
|
@ -353,7 +353,7 @@ def websocket_get_run(
|
||||
if pipeline_id not in pipeline_data.pipeline_debug:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_FOUND,
|
||||
websocket_api.ERR_NOT_FOUND,
|
||||
f"pipeline_id {pipeline_id} not found",
|
||||
)
|
||||
return
|
||||
@ -363,7 +363,7 @@ def websocket_get_run(
|
||||
if pipeline_run_id not in pipeline_debug:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_FOUND,
|
||||
websocket_api.ERR_NOT_FOUND,
|
||||
f"pipeline_run_id {pipeline_run_id} not found",
|
||||
)
|
||||
return
|
||||
|
@ -544,7 +544,7 @@ async def websocket_create_long_lived_access_token(
|
||||
try:
|
||||
access_token = hass.auth.async_create_access_token(refresh_token)
|
||||
except InvalidAuthError as exc:
|
||||
connection.send_error(msg["id"], websocket_api.const.ERR_UNAUTHORIZED, str(exc))
|
||||
connection.send_error(msg["id"], websocket_api.ERR_UNAUTHORIZED, str(exc))
|
||||
return
|
||||
|
||||
connection.send_result(msg["id"], access_token)
|
||||
|
@ -1208,7 +1208,7 @@ def websocket_config(
|
||||
|
||||
if automation is None:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Entity not found"
|
||||
msg["id"], websocket_api.ERR_NOT_FOUND, "Entity not found"
|
||||
)
|
||||
return
|
||||
|
||||
|
@ -642,7 +642,7 @@ async def google_assistant_get(
|
||||
if not state:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_FOUND,
|
||||
websocket_api.ERR_NOT_FOUND,
|
||||
f"{entity_id} unknown",
|
||||
)
|
||||
return
|
||||
@ -651,7 +651,7 @@ async def google_assistant_get(
|
||||
if entity_id in CLOUD_NEVER_EXPOSED_ENTITIES or not entity.is_supported():
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_SUPPORTED,
|
||||
websocket_api.ERR_NOT_SUPPORTED,
|
||||
f"{entity_id} not supported by Google assistant",
|
||||
)
|
||||
return
|
||||
@ -755,7 +755,7 @@ async def alexa_get(
|
||||
):
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_SUPPORTED,
|
||||
websocket_api.ERR_NOT_SUPPORTED,
|
||||
f"{entity_id} not supported by Alexa",
|
||||
)
|
||||
return
|
||||
|
@ -121,7 +121,7 @@ async def websocket_update(
|
||||
if not (user := await hass.auth.async_get_user(msg.pop("user_id"))):
|
||||
connection.send_message(
|
||||
websocket_api.error_message(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "User not found"
|
||||
msg["id"], websocket_api.ERR_NOT_FOUND, "User not found"
|
||||
)
|
||||
)
|
||||
return
|
||||
|
@ -311,9 +311,7 @@ def send_entry_not_found(
|
||||
connection: websocket_api.ActiveConnection, msg_id: int
|
||||
) -> None:
|
||||
"""Send Config entry not found error."""
|
||||
connection.send_error(
|
||||
msg_id, websocket_api.const.ERR_NOT_FOUND, "Config entry not found"
|
||||
)
|
||||
connection.send_error(msg_id, websocket_api.ERR_NOT_FOUND, "Config entry not found")
|
||||
|
||||
|
||||
def get_entry(
|
||||
|
@ -42,7 +42,7 @@ def websocket_list_devices(
|
||||
registry = dr.async_get(hass)
|
||||
# Build start of response message
|
||||
msg_json_prefix = (
|
||||
f'{{"id":{msg["id"]},"type": "{websocket_api.const.TYPE_RESULT}",'
|
||||
f'{{"id":{msg["id"]},"type": "{websocket_api.TYPE_RESULT}",'
|
||||
f'"success":true,"result": ['
|
||||
).encode()
|
||||
# Concatenate cached entity registry item JSON serializations
|
||||
|
@ -43,7 +43,7 @@ def websocket_list_entities(
|
||||
registry = er.async_get(hass)
|
||||
# Build start of response message
|
||||
msg_json_prefix = (
|
||||
f'{{"id":{msg["id"]},"type": "{websocket_api.const.TYPE_RESULT}",'
|
||||
f'{{"id":{msg["id"]},"type": "{websocket_api.TYPE_RESULT}",'
|
||||
'"success":true,"result": ['
|
||||
).encode()
|
||||
# Concatenate cached entity registry item JSON serializations
|
||||
@ -74,7 +74,7 @@ def websocket_list_entities_for_display(
|
||||
registry = er.async_get(hass)
|
||||
# Build start of response message
|
||||
msg_json_prefix = (
|
||||
f'{{"id":{msg["id"]},"type":"{websocket_api.const.TYPE_RESULT}","success":true,'
|
||||
f'{{"id":{msg["id"]},"type":"{websocket_api.TYPE_RESULT}","success":true,'
|
||||
f'"result":{{"entity_categories":{_ENTITY_CATEGORIES_JSON},"entities":['
|
||||
).encode()
|
||||
# Concatenate cached entity registry item JSON serializations
|
||||
|
@ -94,9 +94,7 @@ async def websocket_prepare(
|
||||
agent = async_get_agent(hass, msg.get("agent_id"))
|
||||
|
||||
if agent is None:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Agent not found"
|
||||
)
|
||||
connection.send_error(msg["id"], websocket_api.ERR_NOT_FOUND, "Agent not found")
|
||||
return
|
||||
|
||||
await agent.async_prepare(msg.get("language"))
|
||||
|
@ -369,7 +369,7 @@ def handle_device_errors(
|
||||
await func(hass, connection, msg)
|
||||
except DeviceNotFound:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Device not found"
|
||||
msg["id"], websocket_api.ERR_NOT_FOUND, "Device not found"
|
||||
)
|
||||
|
||||
return with_error_handling
|
||||
|
@ -417,7 +417,7 @@ def ws_expose_entity(
|
||||
None,
|
||||
):
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_ALLOWED, f"can't expose '{blocked}'"
|
||||
msg["id"], websocket_api.ERR_NOT_ALLOWED, f"can't expose '{blocked}'"
|
||||
)
|
||||
return
|
||||
|
||||
|
@ -65,7 +65,7 @@ async def async_device_name(dev_registry, address):
|
||||
def notify_device_not_found(connection, msg, text):
|
||||
"""Notify the caller that the device was not found."""
|
||||
connection.send_message(
|
||||
websocket_api.error_message(msg[ID], websocket_api.const.ERR_NOT_FOUND, text)
|
||||
websocket_api.error_message(msg[ID], websocket_api.ERR_NOT_FOUND, text)
|
||||
)
|
||||
|
||||
|
||||
|
@ -131,7 +131,7 @@ async def ws_project_file_process(
|
||||
except (ValueError, XknxProjectException) as err:
|
||||
# ValueError could raise from file_upload integration
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_HOME_ASSISTANT_ERROR, str(err)
|
||||
msg["id"], websocket_api.ERR_HOME_ASSISTANT_ERROR, str(err)
|
||||
)
|
||||
return
|
||||
|
||||
|
@ -65,7 +65,7 @@ async def handle_integration_log_level(
|
||||
await async_get_integration(hass, msg["integration"])
|
||||
except IntegrationNotFound:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Integration not found"
|
||||
msg["id"], websocket_api.ERR_NOT_FOUND, "Integration not found"
|
||||
)
|
||||
return
|
||||
await async_get_domain_config(hass).settings.async_update(
|
||||
|
@ -717,7 +717,7 @@ def websocket_config(
|
||||
|
||||
if script is None:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Entity not found"
|
||||
msg["id"], websocket_api.ERR_NOT_FOUND, "Entity not found"
|
||||
)
|
||||
return
|
||||
|
||||
|
@ -582,12 +582,12 @@ def websocket_handle_reorder(
|
||||
except NoMatchingShoppingListItem:
|
||||
connection.send_error(
|
||||
msg_id,
|
||||
websocket_api.const.ERR_NOT_FOUND,
|
||||
websocket_api.ERR_NOT_FOUND,
|
||||
"One or more item id(s) not found.",
|
||||
)
|
||||
return
|
||||
except vol.Invalid as err:
|
||||
connection.send_error(msg_id, websocket_api.const.ERR_INVALID_FORMAT, f"{err}")
|
||||
connection.send_error(msg_id, websocket_api.ERR_INVALID_FORMAT, f"{err}")
|
||||
return
|
||||
|
||||
connection.send_result(msg_id)
|
||||
|
@ -344,7 +344,7 @@ def ws_start_preview(
|
||||
connection.send_message(
|
||||
{
|
||||
"id": msg["id"],
|
||||
"type": websocket_api.const.TYPE_RESULT,
|
||||
"type": websocket_api.TYPE_RESULT,
|
||||
"success": False,
|
||||
"error": {"code": "invalid_user_input", "message": errors},
|
||||
}
|
||||
|
@ -44,9 +44,7 @@ async def ws_add_dataset(
|
||||
try:
|
||||
await dataset_store.async_add_dataset(hass, source, tlv)
|
||||
except TLVError as exc:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_INVALID_FORMAT, str(exc)
|
||||
)
|
||||
connection.send_error(msg["id"], websocket_api.ERR_INVALID_FORMAT, str(exc))
|
||||
return
|
||||
|
||||
connection.send_result(msg["id"])
|
||||
@ -94,9 +92,7 @@ async def ws_set_preferred_dataset(
|
||||
try:
|
||||
store.preferred_dataset = dataset_id
|
||||
except KeyError:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "unknown dataset"
|
||||
)
|
||||
connection.send_error(msg["id"], websocket_api.ERR_NOT_FOUND, "unknown dataset")
|
||||
return
|
||||
|
||||
connection.send_result(msg["id"])
|
||||
@ -120,10 +116,10 @@ async def ws_delete_dataset(
|
||||
try:
|
||||
store.async_delete(dataset_id)
|
||||
except KeyError as exc:
|
||||
connection.send_error(msg["id"], websocket_api.const.ERR_NOT_FOUND, str(exc))
|
||||
connection.send_error(msg["id"], websocket_api.ERR_NOT_FOUND, str(exc))
|
||||
return
|
||||
except dataset_store.DatasetPreferredError as exc:
|
||||
connection.send_error(msg["id"], websocket_api.const.ERR_NOT_ALLOWED, str(exc))
|
||||
connection.send_error(msg["id"], websocket_api.ERR_NOT_ALLOWED, str(exc))
|
||||
return
|
||||
|
||||
connection.send_result(msg["id"])
|
||||
@ -145,9 +141,7 @@ async def ws_get_dataset(
|
||||
|
||||
store = await dataset_store.async_get_store(hass)
|
||||
if not (dataset := store.async_get(dataset_id)):
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "unknown dataset"
|
||||
)
|
||||
connection.send_error(msg["id"], websocket_api.ERR_NOT_FOUND, "unknown dataset")
|
||||
return
|
||||
|
||||
connection.send_result(msg["id"], {"tlv": dataset.tlv})
|
||||
|
@ -1114,7 +1114,7 @@ def websocket_get_engine(
|
||||
if not provider:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_FOUND,
|
||||
websocket_api.ERR_NOT_FOUND,
|
||||
f"tts engine {engine_id} not found",
|
||||
)
|
||||
return
|
||||
@ -1149,7 +1149,7 @@ def websocket_list_engine_voices(
|
||||
if not engine_instance:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_FOUND,
|
||||
websocket_api.ERR_NOT_FOUND,
|
||||
f"tts engine {engine_id} not found",
|
||||
)
|
||||
return
|
||||
|
@ -495,14 +495,14 @@ async def websocket_release_notes(
|
||||
|
||||
if entity is None:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Entity not found"
|
||||
msg["id"], websocket_api.ERR_NOT_FOUND, "Entity not found"
|
||||
)
|
||||
return
|
||||
|
||||
if UpdateEntityFeature.RELEASE_NOTES not in entity.supported_features_compat:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_SUPPORTED,
|
||||
websocket_api.ERR_NOT_SUPPORTED,
|
||||
"Entity does not support release notes",
|
||||
)
|
||||
return
|
||||
|
@ -147,7 +147,7 @@ async def websocket_entity_info(
|
||||
|
||||
if entity is None:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Entity not found"
|
||||
msg["id"], websocket_api.ERR_NOT_FOUND, "Entity not found"
|
||||
)
|
||||
return
|
||||
|
||||
@ -156,7 +156,7 @@ async def websocket_entity_info(
|
||||
wake_words = await entity.get_supported_wake_words()
|
||||
except TimeoutError:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_TIMEOUT, "Timeout fetching wake words"
|
||||
msg["id"], websocket_api.ERR_TIMEOUT, "Timeout fetching wake words"
|
||||
)
|
||||
return
|
||||
|
||||
|
@ -16,6 +16,7 @@ from .connection import ActiveConnection, current_connection # noqa: F401
|
||||
from .const import ( # noqa: F401
|
||||
ERR_HOME_ASSISTANT_ERROR,
|
||||
ERR_INVALID_FORMAT,
|
||||
ERR_NOT_ALLOWED,
|
||||
ERR_NOT_FOUND,
|
||||
ERR_NOT_SUPPORTED,
|
||||
ERR_SERVICE_VALIDATION_ERROR,
|
||||
@ -24,6 +25,7 @@ from .const import ( # noqa: F401
|
||||
ERR_UNAUTHORIZED,
|
||||
ERR_UNKNOWN_COMMAND,
|
||||
ERR_UNKNOWN_ERROR,
|
||||
TYPE_RESULT,
|
||||
AsyncWebSocketCommandHandler,
|
||||
WebSocketCommandHandler,
|
||||
)
|
||||
|
@ -443,7 +443,7 @@ async def websocket_get_device(
|
||||
if not (zha_device := zha_gateway.devices.get(ieee)):
|
||||
connection.send_message(
|
||||
websocket_api.error_message(
|
||||
msg[ID], websocket_api.const.ERR_NOT_FOUND, "ZHA Device not found"
|
||||
msg[ID], websocket_api.ERR_NOT_FOUND, "ZHA Device not found"
|
||||
)
|
||||
)
|
||||
return
|
||||
@ -470,7 +470,7 @@ async def websocket_get_group(
|
||||
if not (zha_group := zha_gateway.groups.get(group_id)):
|
||||
connection.send_message(
|
||||
websocket_api.error_message(
|
||||
msg[ID], websocket_api.const.ERR_NOT_FOUND, "ZHA Group not found"
|
||||
msg[ID], websocket_api.ERR_NOT_FOUND, "ZHA Group not found"
|
||||
)
|
||||
)
|
||||
return
|
||||
@ -548,7 +548,7 @@ async def websocket_add_group_members(
|
||||
if not (zha_group := zha_gateway.groups.get(group_id)):
|
||||
connection.send_message(
|
||||
websocket_api.error_message(
|
||||
msg[ID], websocket_api.const.ERR_NOT_FOUND, "ZHA Group not found"
|
||||
msg[ID], websocket_api.ERR_NOT_FOUND, "ZHA Group not found"
|
||||
)
|
||||
)
|
||||
return
|
||||
@ -578,7 +578,7 @@ async def websocket_remove_group_members(
|
||||
if not (zha_group := zha_gateway.groups.get(group_id)):
|
||||
connection.send_message(
|
||||
websocket_api.error_message(
|
||||
msg[ID], websocket_api.const.ERR_NOT_FOUND, "ZHA Group not found"
|
||||
msg[ID], websocket_api.ERR_NOT_FOUND, "ZHA Group not found"
|
||||
)
|
||||
)
|
||||
return
|
||||
@ -1214,7 +1214,7 @@ async def websocket_restore_network_backup(
|
||||
try:
|
||||
await application_controller.backups.restore_backup(backup)
|
||||
except ValueError as err:
|
||||
connection.send_error(msg[ID], websocket_api.const.ERR_INVALID_FORMAT, str(err))
|
||||
connection.send_error(msg[ID], websocket_api.ERR_INVALID_FORMAT, str(err))
|
||||
else:
|
||||
connection.send_result(msg[ID])
|
||||
|
||||
|
@ -619,13 +619,11 @@ class StorageCollectionWebsocket[_StorageCollectionT: StorageCollection]:
|
||||
except vol.Invalid as err:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_INVALID_FORMAT,
|
||||
websocket_api.ERR_INVALID_FORMAT,
|
||||
humanize_error(data, err),
|
||||
)
|
||||
except ValueError as err:
|
||||
connection.send_error(
|
||||
msg["id"], websocket_api.const.ERR_INVALID_FORMAT, str(err)
|
||||
)
|
||||
connection.send_error(msg["id"], websocket_api.ERR_INVALID_FORMAT, str(err))
|
||||
|
||||
async def ws_update_item(
|
||||
self, hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict
|
||||
@ -642,19 +640,17 @@ class StorageCollectionWebsocket[_StorageCollectionT: StorageCollection]:
|
||||
except ItemNotFound:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_FOUND,
|
||||
websocket_api.ERR_NOT_FOUND,
|
||||
f"Unable to find {self.item_id_key} {item_id}",
|
||||
)
|
||||
except vol.Invalid as err:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_INVALID_FORMAT,
|
||||
websocket_api.ERR_INVALID_FORMAT,
|
||||
humanize_error(data, err),
|
||||
)
|
||||
except ValueError as err:
|
||||
connection.send_error(
|
||||
msg_id, websocket_api.const.ERR_INVALID_FORMAT, str(err)
|
||||
)
|
||||
connection.send_error(msg_id, websocket_api.ERR_INVALID_FORMAT, str(err))
|
||||
|
||||
async def ws_delete_item(
|
||||
self, hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict
|
||||
@ -665,7 +661,7 @@ class StorageCollectionWebsocket[_StorageCollectionT: StorageCollection]:
|
||||
except ItemNotFound:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_FOUND,
|
||||
websocket_api.ERR_NOT_FOUND,
|
||||
f"Unable to find {self.item_id_key} {msg[self.item_id_key]}",
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user