mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 10:48:01 +02:00
remove redundant parts of exception translations
This commit is contained in:
@ -46,24 +46,19 @@ async def _async_upload_file(service_call: ServiceCall) -> None:
|
|||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
translation_key="config_entry_not_found",
|
translation_key="config_entry_not_found",
|
||||||
translation_placeholders={"service": service_call.service},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if target_entry.state is not ConfigEntryState.LOADED:
|
if target_entry.state is not ConfigEntryState.LOADED:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
translation_key="config_entry_not_loaded",
|
translation_key="config_entry_not_loaded",
|
||||||
translation_placeholders={"service": service_call.service},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not os.path.isfile(target_file):
|
if not os.path.isfile(target_file):
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
translation_key="file_not_found",
|
translation_key="file_not_found",
|
||||||
translation_placeholders={
|
translation_placeholders={"file": target_file},
|
||||||
"service": service_call.service,
|
|
||||||
"file": target_file,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
coordinator = target_entry.runtime_data
|
coordinator = target_entry.runtime_data
|
||||||
@ -75,11 +70,7 @@ async def _async_upload_file(service_call: ServiceCall) -> None:
|
|||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
translation_key="album_not_found",
|
translation_key="album_not_found",
|
||||||
translation_placeholders={
|
translation_placeholders={"album_id": target_album, "error": str(ex)},
|
||||||
"service": service_call.service,
|
|
||||||
"album_id": target_album,
|
|
||||||
"error": str(ex),
|
|
||||||
},
|
|
||||||
) from ex
|
) from ex
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -92,11 +83,7 @@ async def _async_upload_file(service_call: ServiceCall) -> None:
|
|||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
translation_key="upload_failed",
|
translation_key="upload_failed",
|
||||||
translation_placeholders={
|
translation_placeholders={"file": target_file, "error": str(ex)},
|
||||||
"service": service_call.service,
|
|
||||||
"file": target_file,
|
|
||||||
"error": str(ex),
|
|
||||||
},
|
|
||||||
) from ex
|
) from ex
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,19 +92,19 @@
|
|||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
"config_entry_not_found": {
|
"config_entry_not_found": {
|
||||||
"message": "Failed to perform action \"{service}\". Config entry not found."
|
"message": "Config entry not found."
|
||||||
},
|
},
|
||||||
"config_entry_not_loaded": {
|
"config_entry_not_loaded": {
|
||||||
"message": "Failed to perform action \"{service}\". Config entry not loaded."
|
"message": "Config entry not loaded."
|
||||||
},
|
},
|
||||||
"file_not_found": {
|
"file_not_found": {
|
||||||
"message": "Failed to perform action \"{service}\". File `{file}` not found."
|
"message": "File `{file}` not found."
|
||||||
},
|
},
|
||||||
"album_not_found": {
|
"album_not_found": {
|
||||||
"message": "Failed to perform action \"{service}\". Album with ID `{album_id}` not found ({error})."
|
"message": "Album with ID `{album_id}` not found ({error})."
|
||||||
},
|
},
|
||||||
"upload_failed": {
|
"upload_failed": {
|
||||||
"message": "Failed to perform action \"{service}\". Upload of file `{file}` failed ({error})."
|
"message": "Upload of file `{file}` failed ({error})."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,10 +97,7 @@ async def test_upload_file_config_entry_not_found(
|
|||||||
"""Test upload_file service raising config_entry_not_found."""
|
"""Test upload_file service raising config_entry_not_found."""
|
||||||
await setup_integration(hass, mock_config_entry)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
with pytest.raises(
|
with pytest.raises(ServiceValidationError, match="Config entry not found"):
|
||||||
ServiceValidationError,
|
|
||||||
match='Failed to perform action "upload_file". Config entry not found',
|
|
||||||
):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_UPLOAD_FILE,
|
SERVICE_UPLOAD_FILE,
|
||||||
@ -121,10 +118,7 @@ async def test_upload_file_config_entry_not_loaded(
|
|||||||
mock_config_entry.disabled_by = er.RegistryEntryDisabler.USER
|
mock_config_entry.disabled_by = er.RegistryEntryDisabler.USER
|
||||||
await setup_integration(hass, mock_config_entry)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
with pytest.raises(
|
with pytest.raises(ServiceValidationError, match="Config entry not loaded"):
|
||||||
ServiceValidationError,
|
|
||||||
match='Failed to perform action "upload_file". Config entry not loaded',
|
|
||||||
):
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_UPLOAD_FILE,
|
SERVICE_UPLOAD_FILE,
|
||||||
@ -145,8 +139,7 @@ async def test_upload_file_file_not_found(
|
|||||||
await setup_integration(hass, mock_config_entry)
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
ServiceValidationError,
|
ServiceValidationError, match="File `not_existing.file` not found"
|
||||||
match='Failed to perform action "upload_file". File `not_existing.file` not found',
|
|
||||||
):
|
):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -182,7 +175,7 @@ async def test_upload_file_album_not_found(
|
|||||||
|
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
ServiceValidationError,
|
ServiceValidationError,
|
||||||
match='Failed to perform action "upload_file". Album with id `721e1a4b-aa12-441e-8d3b-5ac7ab283bb6` not found',
|
match="Album with ID `721e1a4b-aa12-441e-8d3b-5ac7ab283bb6` not found",
|
||||||
):
|
):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -217,8 +210,7 @@ async def test_upload_file_upload_failed(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
ServiceValidationError,
|
ServiceValidationError, match=f"Upload of file `{test_file.as_posix()}` failed"
|
||||||
match=f'Failed to perform action "upload_file". Upload of file `{test_file.as_posix()}` failed',
|
|
||||||
):
|
):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -252,8 +244,7 @@ async def test_upload_file_to_album_upload_failed(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
ServiceValidationError,
|
ServiceValidationError, match=f"Upload of file `{test_file.as_posix()}` failed"
|
||||||
match=f'Failed to perform action "upload_file". Upload of file `{test_file.as_posix()}` failed',
|
|
||||||
):
|
):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
Reference in New Issue
Block a user