From 11f86d9e0b0e54a9ef85e0ede2d212cb7c3ee677 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 8 May 2024 14:16:08 -0500 Subject: [PATCH] Improve config entry has already been setup error message (#117091) --- homeassistant/helpers/entity_component.py | 5 ++++- tests/helpers/test_entity_component.py | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index eb54d83e1dd..aae0e2058e4 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -182,7 +182,10 @@ class EntityComponent(Generic[_EntityT]): 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, diff --git a/tests/helpers/test_entity_component.py b/tests/helpers/test_entity_component.py index 60d0774b549..330876aae05 100644 --- a/tests/helpers/test_entity_component.py +++ b/tests/helpers/test_entity_component.py @@ -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 @@ -365,7 +366,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)