Skip to content

Commit a00b4b0

Browse files
committed
refactor: condense duplicate item name warning message into a single, more compact line
1 parent 2c972a9 commit a00b4b0

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

pyomnilogic_local/omnilogic.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,16 @@ def _check_duplicate_item_names(items: Sequence[OmniEquipment[Any, Any]], source
4848
if not duplicate_names:
4949
return None
5050

51-
item = items[0] # Guaranteed to exist if we have duplicates
52-
msg_lines = [f"OmniLogic {source_id} contains multiple items with the same name:"]
51+
duplicates = []
5352
for name in sorted(duplicate_names):
54-
name_items = items_by_name[name]
55-
ids = [str(i.system_id) for i in name_items if i.system_id is not None]
56-
msg_lines.append(f" - {name}: IDs {', '.join(ids)}")
57-
58-
msg_lines.append(
53+
ids = [i.system_id for i in items_by_name[name] if i.system_id is not None]
54+
duplicates.append(f"'{name}' {ids}")
55+
return (
56+
f"OmniLogic {source_id} provided equipment with duplicate names: {', '.join(duplicates)}. "
5957
"Name-based lookups will return the first match. "
60-
"Consider using system_id-based lookups for reliability "
58+
"Consider looking up by system_id (shown in parentheses) for reliability "
6159
"or renaming equipment on the OmniLogic controller to avoid duplicates."
6260
)
63-
return "\n".join(msg_lines)
6461

6562

6663
class OmniLogic:

tests/test_omnilogic.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ def test__check_duplicate_item_names() -> None:
2525
)
2626

2727
assert warning == (
28-
"OmniLogic 127.0.0.1:10444 contains multiple items with the same name:\n"
29-
" - Gas: IDs 3, 4\n"
30-
" - Solar: IDs 1, 2\n"
28+
"OmniLogic 127.0.0.1:10444 provided equipment with duplicate names: 'Gas' [3, 4], 'Solar' [1, 2]. "
3129
"Name-based lookups will return the first match. "
32-
"Consider using system_id-based lookups for reliability "
30+
"Consider looking up by system_id (shown in parentheses) for reliability "
3331
"or renaming equipment on the OmniLogic controller to avoid duplicates."
3432
)
3533

@@ -46,7 +44,7 @@ def test__check_duplicate_item_names_different_host() -> None:
4644
)
4745

4846
assert warning is not None
49-
assert "OmniLogic 127.0.0.2:3000 contains multiple items with the same name:" in warning
47+
assert "OmniLogic 127.0.0.2:3000 provided equipment with duplicate names:" in warning
5048

5149

5250
def test__check_duplicate_item_names_no_duplicates() -> None:

0 commit comments

Comments
 (0)