diff --git a/homeassistant/components/nextbus/config_flow.py b/homeassistant/components/nextbus/config_flow.py index d7149bcc9f4..000dd86eb52 100644 --- a/homeassistant/components/nextbus/config_flow.py +++ b/homeassistant/components/nextbus/config_flow.py @@ -58,7 +58,7 @@ def _get_stop_tags( # Append directions for stops with shared titles for tag, title in tags.items(): if title_counts[title] > 1: - tags[tag] = f"{title} ({stop_directions[tag]})" + tags[tag] = f"{title} ({stop_directions.get(tag, tag)})" return tags diff --git a/tests/components/nextbus/conftest.py b/tests/components/nextbus/conftest.py index a38f3fd850e..0940118c13a 100644 --- a/tests/components/nextbus/conftest.py +++ b/tests/components/nextbus/conftest.py @@ -19,6 +19,8 @@ def mock_nextbus_lists(mock_nextbus: MagicMock) -> MagicMock: "stop": [ {"tag": "5650", "title": "Market St & 7th St"}, {"tag": "5651", "title": "Market St & 7th St"}, + # Error case test. Duplicate title with no unique direction + {"tag": "5652", "title": "Market St & 7th St"}, ], "direction": [ {