diff --git a/homeassistant/exceptions.py b/homeassistant/exceptions.py index 81856f27c450bb..e6ed111c13f4a3 100644 --- a/homeassistant/exceptions.py +++ b/homeassistant/exceptions.py @@ -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 diff --git a/tests/components/trace/test_websocket_api.py b/tests/components/trace/test_websocket_api.py index 5e584de2b4f113..5c5d882b721a4d 100644 --- a/tests/components/trace/test_websocket_api.py +++ b/tests/components/trace/test_websocket_api.py @@ -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 @@ def next_id(): _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 @@ def next_id(): 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 @@ def next_id(): 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" diff --git a/tests/helpers/test_script.py b/tests/helpers/test_script.py index 0e658f3570274f..95bb3f813e4480 100644 --- a/tests/helpers/test_script.py +++ b/tests/helpers/test_script.py @@ -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.""" diff --git a/tests/test_core.py b/tests/test_core.py index f95a2104ff5524..61852c69e8bc9d 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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(