diff --git a/homeassistant/components/google_travel_time/helpers.py b/homeassistant/components/google_travel_time/helpers.py index 3af4073bef6..70f9300c92f 100644 --- a/homeassistant/components/google_travel_time/helpers.py +++ b/homeassistant/components/google_travel_time/helpers.py @@ -46,7 +46,7 @@ def convert_to_waypoint(hass: HomeAssistant, location: str) -> Waypoint | None: try: formatted_coordinates = coordinates.split(",") vol.Schema(cv.gps(formatted_coordinates)) - except (AttributeError, vol.ExactSequenceInvalid): + except (AttributeError, vol.Invalid): return Waypoint(address=location) return Waypoint( location=Location( diff --git a/tests/components/google_travel_time/test_helpers.py b/tests/components/google_travel_time/test_helpers.py new file mode 100644 index 00000000000..058cb214ed7 --- /dev/null +++ b/tests/components/google_travel_time/test_helpers.py @@ -0,0 +1,46 @@ +"""Tests for google_travel_time.helpers.""" + +from google.maps.routing_v2 import Location, Waypoint +from google.type import latlng_pb2 +import pytest + +from homeassistant.components.google_travel_time import helpers +from homeassistant.core import HomeAssistant + + +@pytest.mark.parametrize( + ("location", "expected_result"), + [ + ( + "12.34,56.78", + Waypoint( + location=Location( + lat_lng=latlng_pb2.LatLng( + latitude=12.34, + longitude=56.78, + ) + ) + ), + ), + ( + "12.34, 56.78", + Waypoint( + location=Location( + lat_lng=latlng_pb2.LatLng( + latitude=12.34, + longitude=56.78, + ) + ) + ), + ), + ("Some Address", Waypoint(address="Some Address")), + ("Some Street 1, 12345 City", Waypoint(address="Some Street 1, 12345 City")), + ], +) +def test_convert_to_waypoint_coordinates( + hass: HomeAssistant, location: str, expected_result: Waypoint +) -> None: + """Test convert_to_waypoint returns correct Waypoint for coordinates or address.""" + waypoint = helpers.convert_to_waypoint(hass, location) + + assert waypoint == expected_result