From dc38d152dfbc70226df8d54859819cedd7662e30 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Thu, 21 Mar 2024 06:54:29 +0100 Subject: [PATCH] Fetch ServiceNotFound message from translation cache (#113893) --- homeassistant/exceptions.py | 1 - tests/test_core.py | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/homeassistant/exceptions.py b/homeassistant/exceptions.py index e94d5fd6b57..81856f27c45 100644 --- a/homeassistant/exceptions.py +++ b/homeassistant/exceptions.py @@ -261,7 +261,6 @@ class ServiceNotFound(HomeAssistantError): """Initialize error.""" super().__init__( self, - f"Service {domain}.{service} not found.", translation_domain="homeassistant", translation_key="service_not_found", translation_placeholders={"domain": domain, "service": service}, diff --git a/tests/test_core.py b/tests/test_core.py index ad67adb78b9..f95a2104ff5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1676,8 +1676,18 @@ async def test_serviceregistry_service_that_not_exists(hass: HomeAssistant) -> N await hass.async_block_till_done() assert len(calls_remove) == 0 - with pytest.raises(ServiceNotFound): + with pytest.raises(ServiceNotFound) as exc: await hass.services.async_call("test_do_not", "exist", {}) + assert exc.value.translation_domain == "homeassistant" + assert exc.value.translation_key == "service_not_found" + assert exc.value.translation_placeholders == { + "domain": "test_do_not", + "service": "exist", + } + assert exc.value.domain == "test_do_not" + assert exc.value.service == "exist" + + assert str(exc.value) == "Service test_do_not.exist not found." async def test_serviceregistry_async_service_raise_exception(