From befc73c53e564c262d68ffee6daddac125c07646 Mon Sep 17 00:00:00 2001 From: discountchubbs Date: Wed, 29 Oct 2025 20:03:19 -0700 Subject: [PATCH] more --- sunnypilot/navd/constants.py | 2 +- sunnypilot/navd/event_builder.py | 7 +++++-- sunnypilot/navd/tests/test_event_builder.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sunnypilot/navd/constants.py b/sunnypilot/navd/constants.py index 916270c7af..eaa29f9cdc 100644 --- a/sunnypilot/navd/constants.py +++ b/sunnypilot/navd/constants.py @@ -8,7 +8,7 @@ See the LICENSE.md file in the root directory for more details. class NAV_CV: """ These distances are expected in meters format and convert to desired format """ SHORT_DISTANCE_METERS = 200.0 - QUARTER_MILE = 402.0 + POINT_ONE_MILE = 160.9344 METERS_TO_KILO = 1000 # divide m by this METERS_TO_MILE = 1609.344 # divide m by this METERS_TO_FEET = 3.280839895 # multiply m by this diff --git a/sunnypilot/navd/event_builder.py b/sunnypilot/navd/event_builder.py index 2739246fd2..7ed83b1caf 100644 --- a/sunnypilot/navd/event_builder.py +++ b/sunnypilot/navd/event_builder.py @@ -28,8 +28,11 @@ class EventBuilder: dist = f'{int(m.distance)}m,' else: dist = f'{m.distance / NAV_CV.METERS_TO_MILE:.1f} mi,' - if m.distance < NAV_CV.QUARTER_MILE: - dist = f'{int(m.distance * NAV_CV.METERS_TO_FEET)}ft,' + if m.distance < NAV_CV.POINT_ONE_MILE: + if m.distance * NAV_CV.METERS_TO_FEET < 250.0: + dist = f'{round((m.distance * NAV_CV.METERS_TO_FEET) / 50) * 50}ft,' + else: + dist = f'{round((m.distance * NAV_CV.METERS_TO_FEET) / 100) * 100}ft,' if m.type == 'arrive' or m.type == 'depart': base_msg = banner diff --git a/sunnypilot/navd/tests/test_event_builder.py b/sunnypilot/navd/tests/test_event_builder.py index 7e2e1bbcc6..94ff1ca71e 100644 --- a/sunnypilot/navd/tests/test_event_builder.py +++ b/sunnypilot/navd/tests/test_event_builder.py @@ -61,6 +61,16 @@ class TestEventBuilder: }] assert events == expected + def test_distance_condition_imperial(self): + nav_msg = self.create_nav_msg() + nav_msg.allManeuvers[1] = custom.Navigationd.Maneuver.new_message(distance=160.0, type='continue', modifier='straight', instruction='1234 Apple Way') + events = EventBuilder.build_navigation_events(MockSM(nav_msg), False) + expected = [{ + 'name': custom.OnroadEventSP.EventName.navigationBanner, + 'message': 'For 500ft, Continue on 1234 Apple Way', + }] + assert events == expected + def test_upcoming_turn_override(self): nav_msg = self.create_nav_msg(upcoming_turn='left') events = EventBuilder.build_navigation_events(MockSM(nav_msg))