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

Improve config entry has already been setup error message #117091

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion homeassistant/helpers/entity_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ async def async_setup_entry(self, config_entry: ConfigEntry) -> bool:
key = config_entry.entry_id

if key in self._platforms:
raise ValueError("Config entry has already been setup!")
raise ValueError(
f"Config entry {config_entry.title} ({key}) for "
f"{platform_type}.{self.domain} has already been setup!"
)

self._platforms[key] = self._async_init_entity_platform(
platform_type,
Expand Down
9 changes: 8 additions & 1 deletion tests/helpers/test_entity_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections import OrderedDict
from datetime import timedelta
import logging
import re
from unittest.mock import AsyncMock, Mock, patch

from freezegun import freeze_time
Expand Down Expand Up @@ -363,7 +364,13 @@ async def test_setup_entry_fails_duplicate(hass: HomeAssistant) -> None:

assert await component.async_setup_entry(entry)

with pytest.raises(ValueError):
with pytest.raises(
ValueError,
match=re.escape(
f"Config entry Mock Title ({entry.entry_id}) for "
"entry_domain.test_domain has already been setup!"
),
):
await component.async_setup_entry(entry)


Expand Down