From 0f43476d0347dc3c56d4974e3629a398f82880cf Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Mon, 29 Jun 2020 18:25:01 -0600 Subject: [PATCH] Fix Tile location accuracy bug (#37233) Co-authored-by: Paulus Schoutsen --- .../components/tile/device_tracker.py | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/tile/device_tracker.py b/homeassistant/components/tile/device_tracker.py index 910732f7c04..5b0065b2c4e 100644 --- a/homeassistant/components/tile/device_tracker.py +++ b/homeassistant/components/tile/device_tracker.py @@ -84,13 +84,26 @@ class TileDeviceTracker(TileEntity, TrackerEntity): Value in meters. """ - return round( - ( - self._tile["last_tile_state"]["h_accuracy"] - + self._tile["last_tile_state"]["v_accuracy"] + state = self._tile["last_tile_state"] + h_accuracy = state.get("h_accuracy") + v_accuracy = state.get("v_accuracy") + + if h_accuracy is not None and v_accuracy is not None: + return round( + ( + self._tile["last_tile_state"]["h_accuracy"] + + self._tile["last_tile_state"]["v_accuracy"] + ) + / 2 ) - / 2 - ) + + if h_accuracy is not None: + return h_accuracy + + if v_accuracy is not None: + return v_accuracy + + return None @property def latitude(self) -> float: