From 1e4d10efe1188c3405b5c66f1def3e4b96cdc096 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 8 Jan 2024 21:51:56 -1000 Subject: [PATCH] Add caching to the distance calculation utility (#107626) --- homeassistant/util/location.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/util/location.py b/homeassistant/util/location.py index b2ef7330660..9e9c434822e 100644 --- a/homeassistant/util/location.py +++ b/homeassistant/util/location.py @@ -5,6 +5,7 @@ detect_location_info and elevation are mocked by default during tests. from __future__ import annotations import asyncio +from functools import lru_cache import math from typing import Any, NamedTuple @@ -57,6 +58,7 @@ async def async_detect_location_info( return LocationInfo(**data) +@lru_cache def distance( lat1: float | None, lon1: float | None, lat2: float, lon2: float ) -> float | None: