mirror of
https://github.com/home-assistant/core.git
synced 2025-07-04 11:57:05 +00:00
Support addresses with comma in google_travel_time (#145663)
Support addresses with comma
This commit is contained in:
parent
481639bcf9
commit
07fd1f99df
@ -46,7 +46,7 @@ def convert_to_waypoint(hass: HomeAssistant, location: str) -> Waypoint | None:
|
|||||||
try:
|
try:
|
||||||
formatted_coordinates = coordinates.split(",")
|
formatted_coordinates = coordinates.split(",")
|
||||||
vol.Schema(cv.gps(formatted_coordinates))
|
vol.Schema(cv.gps(formatted_coordinates))
|
||||||
except (AttributeError, vol.ExactSequenceInvalid):
|
except (AttributeError, vol.Invalid):
|
||||||
return Waypoint(address=location)
|
return Waypoint(address=location)
|
||||||
return Waypoint(
|
return Waypoint(
|
||||||
location=Location(
|
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
|
Loading…
x
Reference in New Issue
Block a user