Fetch ServiceNotFound message from translation cache and fix super (#114084)
* Fetch ServiceNotFound message from translation cache and fix super * Fix tests trace component * Fix script errorspull/113088/head^2
parent
6371b344b9
commit
67ab49b825
|
@ -260,17 +260,13 @@ class ServiceNotFound(HomeAssistantError):
|
|||
def __init__(self, domain: str, service: str) -> None:
|
||||
"""Initialize error."""
|
||||
super().__init__(
|
||||
self,
|
||||
translation_domain="homeassistant",
|
||||
translation_key="service_not_found",
|
||||
translation_placeholders={"domain": domain, "service": service},
|
||||
)
|
||||
self.domain = domain
|
||||
self.service = service
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""Return string representation."""
|
||||
return f"Service {self.domain}.{self.service} not found."
|
||||
self.generate_message = True
|
||||
|
||||
|
||||
class MaxLengthExceeded(HomeAssistantError):
|
||||
|
@ -279,7 +275,6 @@ class MaxLengthExceeded(HomeAssistantError):
|
|||
def __init__(self, value: str, property_name: str, max_length: int) -> None:
|
||||
"""Initialize error."""
|
||||
super().__init__(
|
||||
self,
|
||||
translation_domain="homeassistant",
|
||||
translation_key="max_length_exceeded",
|
||||
translation_placeholders={
|
||||
|
@ -300,7 +295,6 @@ class DependencyError(HomeAssistantError):
|
|||
def __init__(self, failed_dependencies: list[str]) -> None:
|
||||
"""Initialize error."""
|
||||
super().__init__(
|
||||
self,
|
||||
f"Could not setup dependencies: {', '.join(failed_dependencies)}",
|
||||
)
|
||||
self.failed_dependencies = failed_dependencies
|
||||
|
|
|
@ -132,6 +132,7 @@ async def test_get_trace(
|
|||
enable_custom_integrations: None,
|
||||
) -> None:
|
||||
"""Test tracing a script or automation."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
id = 1
|
||||
|
||||
def next_id():
|
||||
|
@ -206,7 +207,7 @@ async def test_get_trace(
|
|||
_assert_raw_config(domain, sun_config, trace)
|
||||
assert trace["blueprint_inputs"] is None
|
||||
assert trace["context"]
|
||||
assert trace["error"] == "Service test.automation not found."
|
||||
assert trace["error"] == "Service test.automation not found"
|
||||
assert trace["state"] == "stopped"
|
||||
assert trace["script_execution"] == "error"
|
||||
assert trace["item_id"] == "sun"
|
||||
|
@ -808,6 +809,7 @@ async def test_list_traces(
|
|||
script_execution,
|
||||
) -> None:
|
||||
"""Test listing script and automation traces."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
id = 1
|
||||
|
||||
def next_id():
|
||||
|
@ -894,7 +896,7 @@ async def test_list_traces(
|
|||
assert len(_find_traces(response["result"], domain, "sun")) == 1
|
||||
trace = _find_traces(response["result"], domain, "sun")[0]
|
||||
assert trace["last_step"] == last_step[0].format(prefix=prefix)
|
||||
assert trace["error"] == "Service test.automation not found."
|
||||
assert trace["error"] == "Service test.automation not found"
|
||||
assert trace["state"] == "stopped"
|
||||
assert trace["script_execution"] == script_execution[0]
|
||||
assert trace["timestamp"]
|
||||
|
@ -1574,6 +1576,7 @@ async def test_trace_blueprint_automation(
|
|||
enable_custom_integrations: None,
|
||||
) -> None:
|
||||
"""Test trace of blueprint automation."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
id = 1
|
||||
|
||||
def next_id():
|
||||
|
@ -1633,7 +1636,7 @@ async def test_trace_blueprint_automation(
|
|||
assert trace["config"]["id"] == "sun"
|
||||
assert trace["blueprint_inputs"] == sun_config
|
||||
assert trace["context"]
|
||||
assert trace["error"] == "Service test.automation not found."
|
||||
assert trace["error"] == "Service test.automation not found"
|
||||
assert trace["state"] == "stopped"
|
||||
assert trace["script_execution"] == "error"
|
||||
assert trace["item_id"] == "sun"
|
||||
|
|
|
@ -3536,6 +3536,7 @@ async def test_parallel_error(
|
|||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test parallel action failure handling."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
events = async_capture_events(hass, "test_event")
|
||||
sequence = cv.SCRIPT_SCHEMA(
|
||||
{
|
||||
|
@ -3552,10 +3553,10 @@ async def test_parallel_error(
|
|||
assert len(events) == 0
|
||||
|
||||
expected_trace = {
|
||||
"0": [{"error": "Service epic.failure not found."}],
|
||||
"0": [{"error": "Service epic.failure not found"}],
|
||||
"0/parallel/0/sequence/0": [
|
||||
{
|
||||
"error": "Service epic.failure not found.",
|
||||
"error": "Service epic.failure not found",
|
||||
"result": {
|
||||
"params": {
|
||||
"domain": "epic",
|
||||
|
@ -3589,6 +3590,7 @@ async def test_last_triggered(hass: HomeAssistant) -> None:
|
|||
|
||||
async def test_propagate_error_service_not_found(hass: HomeAssistant) -> None:
|
||||
"""Test that a script aborts when a service is not found."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
event = "test_event"
|
||||
events = async_capture_events(hass, event)
|
||||
sequence = cv.SCRIPT_SCHEMA([{"service": "test.script"}, {"event": event}])
|
||||
|
@ -3603,7 +3605,7 @@ async def test_propagate_error_service_not_found(hass: HomeAssistant) -> None:
|
|||
expected_trace = {
|
||||
"0": [
|
||||
{
|
||||
"error": "Service test.script not found.",
|
||||
"error": "Service test.script not found",
|
||||
"result": {
|
||||
"params": {
|
||||
"domain": "test",
|
||||
|
@ -5419,6 +5421,7 @@ async def test_continue_on_error_with_stop(hass: HomeAssistant) -> None:
|
|||
|
||||
async def test_continue_on_error_automation_issue(hass: HomeAssistant) -> None:
|
||||
"""Test continue on error doesn't block action automation errors."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
sequence = cv.SCRIPT_SCHEMA(
|
||||
[
|
||||
{
|
||||
|
@ -5436,7 +5439,7 @@ async def test_continue_on_error_automation_issue(hass: HomeAssistant) -> None:
|
|||
{
|
||||
"0": [
|
||||
{
|
||||
"error": "Service service.not_found not found.",
|
||||
"error": "Service service.not_found not found",
|
||||
"result": {
|
||||
"params": {
|
||||
"domain": "service",
|
||||
|
@ -5455,6 +5458,7 @@ async def test_continue_on_error_automation_issue(hass: HomeAssistant) -> None:
|
|||
|
||||
async def test_continue_on_error_unknown_error(hass: HomeAssistant) -> None:
|
||||
"""Test continue on error doesn't block unknown errors from e.g., libraries."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
|
||||
class MyLibraryError(Exception):
|
||||
"""My custom library error."""
|
||||
|
|
|
@ -1670,6 +1670,7 @@ async def test_serviceregistry_remove_service(hass: HomeAssistant) -> None:
|
|||
|
||||
async def test_serviceregistry_service_that_not_exists(hass: HomeAssistant) -> None:
|
||||
"""Test remove service that not exists."""
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
calls_remove = async_capture_events(hass, EVENT_SERVICE_REMOVED)
|
||||
assert not hass.services.has_service("test_xxx", "test_yyy")
|
||||
hass.services.async_remove("test_xxx", "test_yyy")
|
||||
|
@ -1687,7 +1688,7 @@ async def test_serviceregistry_service_that_not_exists(hass: HomeAssistant) -> N
|
|||
assert exc.value.domain == "test_do_not"
|
||||
assert exc.value.service == "exist"
|
||||
|
||||
assert str(exc.value) == "Service test_do_not.exist not found."
|
||||
assert str(exc.value) == "Service test_do_not.exist not found"
|
||||
|
||||
|
||||
async def test_serviceregistry_async_service_raise_exception(
|
||||
|
|
Loading…
Reference in New Issue