Support addresses with comma in google_travel_time (#145663)

Support addresses with comma
This commit is contained in:
Kevin Stillhammer
2025-05-27 18:53:45 +02:00
committed by GitHub
parent 481639bcf9
commit 07fd1f99df
2 changed files with 47 additions and 1 deletions

View File

@ -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(

View File

@ -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