Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch ServiceNotFound message from translation cache and fix super #114084

Merged
merged 4 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions homeassistant/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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={
Expand All @@ -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
3 changes: 2 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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(
Expand Down
Loading