File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
homeassistant/components/proximity Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -164,16 +164,21 @@ def _calc_distance_to_zone(
164164 )
165165 return None
166166
167- distance_to_zone = distance (
167+ distance_to_centre = distance (
168168 zone .attributes [ATTR_LATITUDE ],
169169 zone .attributes [ATTR_LONGITUDE ],
170170 latitude ,
171171 longitude ,
172172 )
173173
174174 # it is ensured, that distance can't be None, since zones must have lat/lon coordinates
175- assert distance_to_zone is not None
176- return round (distance_to_zone )
175+ assert distance_to_centre is not None
176+
177+ zone_radius : float = zone .attributes ["radius" ]
178+ distance_to_edge : int = round (distance_to_centre - zone_radius )
179+ # return 0 if distance to edge is negative as that means the device is located inside the zone
180+ # but the device's current zone is a different one than the zone in this distance calculation
181+ return max (distance_to_edge , 0 )
177182
178183 def _calc_direction_of_travel (
179184 self ,
You can’t perform that action at this time.
0 commit comments