mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add helpers.location.coordinates (#37234)
This commit is contained in:
@@ -43,3 +43,64 @@ def test_closest_returns_closest():
|
||||
state2 = State("light.test", "on", {ATTR_LATITUDE: 125.45, ATTR_LONGITUDE: 125.45})
|
||||
|
||||
assert state == location.closest(123.45, 123.45, [state, state2])
|
||||
|
||||
|
||||
async def test_coordinates_function_as_attributes(hass):
|
||||
"""Test coordinates function."""
|
||||
hass.states.async_set(
|
||||
"test.object", "happy", {"latitude": 32.87336, "longitude": -117.22943}
|
||||
)
|
||||
assert location.find_coordinates(hass, "test.object") == "32.87336,-117.22943"
|
||||
|
||||
|
||||
async def test_coordinates_function_as_state(hass):
|
||||
"""Test coordinates function."""
|
||||
hass.states.async_set("test.object", "32.87336,-117.22943")
|
||||
assert location.find_coordinates(hass, "test.object") == "32.87336,-117.22943"
|
||||
|
||||
|
||||
async def test_coordinates_function_device_tracker_in_zone(hass):
|
||||
"""Test coordinates function."""
|
||||
hass.states.async_set(
|
||||
"zone.home", "zoning", {"latitude": 32.87336, "longitude": -117.22943},
|
||||
)
|
||||
hass.states.async_set("device_tracker.device", "home")
|
||||
assert (
|
||||
location.find_coordinates(hass, "device_tracker.device")
|
||||
== "32.87336,-117.22943"
|
||||
)
|
||||
|
||||
|
||||
async def test_coordinates_function_device_tracker_from_input_select(hass):
|
||||
"""Test coordinates function."""
|
||||
hass.states.async_set(
|
||||
"input_select.select",
|
||||
"device_tracker.device",
|
||||
{"options": "device_tracker.device"},
|
||||
)
|
||||
hass.states.async_set("device_tracker.device", "32.87336,-117.22943")
|
||||
assert (
|
||||
location.find_coordinates(hass, "input_select.select") == "32.87336,-117.22943"
|
||||
)
|
||||
|
||||
|
||||
def test_coordinates_function_returns_none_on_recursion(hass):
|
||||
"""Test coordinates function."""
|
||||
hass.states.async_set(
|
||||
"test.first", "test.second",
|
||||
)
|
||||
hass.states.async_set("test.second", "test.first")
|
||||
assert location.find_coordinates(hass, "test.first") is None
|
||||
|
||||
|
||||
async def test_coordinates_function_returns_none_if_invalid_coord(hass):
|
||||
"""Test test_coordinates function."""
|
||||
hass.states.async_set(
|
||||
"test.object", "abc",
|
||||
)
|
||||
assert location.find_coordinates(hass, "test.object") is None
|
||||
|
||||
|
||||
def test_coordinates_function_returns_none_if_invalid_input(hass):
|
||||
"""Test test_coordinates function."""
|
||||
assert location.find_coordinates(hass, "test.abc") is None
|
||||
|
||||
Reference in New Issue
Block a user