Add test showing zone.async_active_zone prefers zone closest to center (#173099)

This commit is contained in:
Erik Montnemery
2026-06-05 15:27:44 +02:00
committed by GitHub
parent 3996db289d
commit 085f794407
+41
View File
@@ -221,6 +221,47 @@ async def test_active_zone_prefers_smaller_zone_if_same_distance_2(
assert in_zones == ["zone.smallest_zone"]
async def test_active_zone_prefers_closer_zone_over_smaller_zone(
hass: HomeAssistant,
) -> None:
"""Test the closest containing zone wins over a smaller, farther one.
A larger zone is centered on the point (distance 0) while a smaller zone is
offset but still contains the point. The larger zone is closer to its center,
so it is preferred.
"""
latitude = 32.880600
longitude = -117.237561
assert await setup.async_setup_component(
hass,
zone.DOMAIN,
{
"zone": [
{
"name": "Big Zone",
"latitude": latitude,
"longitude": longitude,
"radius": 1000,
},
{
# Offset ~111 m north; its 200 m radius still contains the
# point. Smaller than Big Zone, but farther from its center.
"name": "Small Zone",
"latitude": latitude + 0.001,
"longitude": longitude,
"radius": 200,
},
]
},
)
active_zone = zone.async_active_zone(hass, latitude, longitude)
assert active_zone.entity_id == "zone.big_zone"
active_zone, in_zones = zone.async_in_zones(hass, latitude, longitude)
assert active_zone.entity_id == "zone.big_zone"
assert in_zones == ["zone.big_zone", "zone.small_zone"]
async def test_in_zone_works_for_passive_zones(hass: HomeAssistant) -> None:
"""Test working in passive zones."""
latitude = 32.880600