mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 09:31:51 +02:00
Support addresses with comma in google_travel_time (#145663)
Support addresses with comma
This commit is contained in:
committed by
GitHub
parent
481639bcf9
commit
07fd1f99df
@ -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(
|
||||
|
46
tests/components/google_travel_time/test_helpers.py
Normal file
46
tests/components/google_travel_time/test_helpers.py
Normal 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
|
Reference in New Issue
Block a user