mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix zone radius calculation when radius is not 0 (#110354)
This commit is contained in:
parent
4bcfa9e315
commit
29146326fa
@ -135,7 +135,7 @@ def async_active_zone(
|
|||||||
is None
|
is None
|
||||||
# Skip zone that are outside the radius aka the
|
# Skip zone that are outside the radius aka the
|
||||||
# lat/long is outside the zone
|
# lat/long is outside the zone
|
||||||
or not (zone_dist - (radius := zone_attrs[ATTR_RADIUS]) < radius)
|
or not (zone_dist - (zone_radius := zone_attrs[ATTR_RADIUS]) < radius)
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ def async_active_zone(
|
|||||||
zone_dist < min_dist
|
zone_dist < min_dist
|
||||||
or (
|
or (
|
||||||
# If same distance, prefer smaller zone
|
# If same distance, prefer smaller zone
|
||||||
zone_dist == min_dist and radius < closest.attributes[ATTR_RADIUS]
|
zone_dist == min_dist and zone_radius < closest.attributes[ATTR_RADIUS]
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
@ -228,6 +228,46 @@ async def test_in_zone_works_for_passive_zones(hass: HomeAssistant) -> None:
|
|||||||
assert zone.in_zone(hass.states.get("zone.passive_zone"), latitude, longitude)
|
assert zone.in_zone(hass.states.get("zone.passive_zone"), latitude, longitude)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_active_zone_with_non_zero_radius(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
|
"""Test async_active_zone with a non-zero radius."""
|
||||||
|
latitude = 32.880600
|
||||||
|
longitude = -117.237561
|
||||||
|
|
||||||
|
assert await setup.async_setup_component(
|
||||||
|
hass,
|
||||||
|
zone.DOMAIN,
|
||||||
|
{
|
||||||
|
"zone": [
|
||||||
|
{
|
||||||
|
"name": "Small Zone",
|
||||||
|
"latitude": 32.980600,
|
||||||
|
"longitude": -117.137561,
|
||||||
|
"radius": 50000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Big Zone",
|
||||||
|
"latitude": 32.980600,
|
||||||
|
"longitude": -117.137561,
|
||||||
|
"radius": 100000,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
home_state = hass.states.get("zone.home")
|
||||||
|
assert home_state.attributes["radius"] == 100
|
||||||
|
assert home_state.attributes["latitude"] == 32.87336
|
||||||
|
assert home_state.attributes["longitude"] == -117.22743
|
||||||
|
|
||||||
|
active = zone.async_active_zone(hass, latitude, longitude, 5000)
|
||||||
|
assert active.entity_id == "zone.home"
|
||||||
|
|
||||||
|
active = zone.async_active_zone(hass, latitude, longitude, 0)
|
||||||
|
assert active.entity_id == "zone.small_zone"
|
||||||
|
|
||||||
|
|
||||||
async def test_core_config_update(hass: HomeAssistant) -> None:
|
async def test_core_config_update(hass: HomeAssistant) -> None:
|
||||||
"""Test updating core config will update home zone."""
|
"""Test updating core config will update home zone."""
|
||||||
assert await setup.async_setup_component(hass, "zone", {})
|
assert await setup.async_setup_component(hass, "zone", {})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user