Skip to content

Commit

Permalink
Log type as well as value for unique_id checks (#129575)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 31, 2024
1 parent 6a32722 commit 696efe3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion homeassistant/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,11 +1638,12 @@ def check_unique_id(self, entry: ConfigEntry) -> None:
_LOGGER.error(
(
"Config entry '%s' from integration %s has an invalid unique_id"
" '%s', please %s"
" '%s' of type %s when a string is expected, please %s"
),
entry.title,
entry.domain,
entry.unique_id,
type(entry.unique_id).__name__,
report_issue,
)
else:
Expand Down
8 changes: 5 additions & 3 deletions tests/test_config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5447,16 +5447,17 @@ async def test_string_unique_id_no_warning(


@pytest.mark.parametrize(
"unique_id",
("unique_id", "type_name"),
[
(123),
(2.3),
(123, "int"),
(2.3, "float"),
],
)
async def test_hashable_unique_id(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
unique_id: Any,
type_name: str,
) -> None:
"""Test the ConfigEntryItems user dict handles hashable non string unique_id."""
entries = config_entries.ConfigEntryItems(hass)
Expand All @@ -5477,6 +5478,7 @@ async def test_hashable_unique_id(

assert (
"Config entry 'title' from integration test has an invalid unique_id"
f" '{unique_id}' of type {type_name} when a string is expected"
) in caplog.text

assert entry.entry_id in entries
Expand Down

0 comments on commit 696efe3

Please sign in to comment.