Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Fix GPS sensor update throttling for device tracking - #35

Draft
JOHLC with Copilot wants to merge 3 commits into
v2025.09.2-devfrom
copilot/fix-gps-data-refresh-rate-again
Draft

Fix GPS sensor update throttling for device tracking#35
JOHLC with Copilot wants to merge 3 commits into
v2025.09.2-devfrom
copilot/fix-gps-data-refresh-rate-again

Conversation

Copilot AI commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

Fix GPS Data Slow Sensor Refresh ✅

Issue: GPS data (latitude and longitude) not updating as frequently as other sensors. Sometimes only one update in a 20min drive. Breaks functionality as a device tracker.

Root Cause: GPS sensors had a significance threshold (0.00001 degrees) that could prevent updates when values changed by very small amounts or when the vehicle was stationary. Additionally, GPS sensors were experiencing flip-flopping where values would revert to previous values immediately after updating.

Changes Made:

  • Removed significance threshold for GPS sensors
  • GPS sensors now update on every value change (not just significant changes)
  • Fixed flip-flopping by checking _attr_native_value instead of _last_reported_value
  • Added debug logging for GPS data reception and updates to aid troubleshooting
  • Updated tests to verify GPS sensors update even with identical values
  • All 50 tests pass
  • Code formatted with Black and linted with Ruff
  • Security scan passed (0 alerts)

How It Works:

  • GPS sensors (PIDs 0xFF1005 longitude and 0xFF1006 latitude) bypass throttling and debouncing
  • GPS sensors update immediately on every data change for real-time device tracking
  • GPS sensors check against current state (_attr_native_value) to prevent flip-flopping
  • Debug logging helps identify when GPS data is received and when sensors update
  • Non-GPS sensors continue to use throttling (15s) and debouncing to prevent database spam

Technical Details:

  • Modified async_on_update() method to remove significance threshold check for GPS sensors
  • GPS sensors now use simple inequality check (!=) against _attr_native_value instead of _last_reported_value
  • This prevents flip-flopping where the sensor state would revert to previous values
  • The fix matches the flip-flop prevention already implemented for non-GPS sensors (line 738)
  • Added debug logging at data reception and sensor update points
  • GPS sensors skip the value buffer used by other sensors for debouncing

Testing:

  • All 50 tests pass including:
    • 5 GPS-specific tests verify immediate updates without throttling
    • Flip-flop prevention tests verify no duplicate consecutive values
    • Non-GPS sensors still correctly use throttling to prevent excessive updates
    • Debouncing still works for non-GPS sensors to filter noise

Security:

  • CodeQL scan completed: 0 alerts found
  • No new vulnerabilities introduced
Original prompt

This section details on the original issue you should resolve

<issue_title>GPS data slow sensor refresh</issue_title>
<issue_description>Integration Version
2.0

Home Assistant Version

2025.11.1

Installation Method
HACS

Platform
HAOS

Describe the bug
GPS data (latitude and longitude) not updating as frequently as other sensors. Sometimes only one update in a 20min drive. Breaks functionality as a device tracker.

To Reproduce
Steps to reproduce the behavior:

  1. Setup successful, upload successful
  2. Include latitude and longitude data
  3. Compare lat and long refresh rate to other torque sensors

Torque App Settings
Update interval 1min

Vehicle Information
(Optional) Vehicle make, model, year, and OBD adapter type.

Additional context
GPS on device running torque pro confirmed working fine. Using GPS widget in torque which shows correct GPS data.
Torque status information shows
GPS Status 'GPS is working'
Web Upload Status - Last Message: None </issue_description>

Comments on the Issue (you are @copilot in this section)

@JOHLC Hi there

Thanks for sharing.
I dont have too much time to work on this right now, and it is still very early in it's development.

Will look into it when I am able. In the meantime, lets see what Copilot thinks. </comment_new>
<comment_new>@JOHLC
If you are feeling adventurous, try the latest alpha release that Copilot spit out
https://github.com/JOHLC/ha-torque-2.0/releases/tag/v2025.10.1-alpha8

I am also going to install it and test in on my trip</comment_new>
<comment_new>@JOHLC
Thanks so much for the test and reply back. I have been seeing that same behavior across other sensors as well and have not been able to figure it out yet.
I will update you once I have something more to share. </comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Remove significance threshold (0.00001) for GPS sensors
- GPS sensors now update on every value change for proper location tracking
- Add debug logging for GPS data reception and updates
- Update tests to verify GPS sensors update even with identical values

Co-authored-by: JOHLC <[email protected]>
Copilot AI changed the title [WIP] Fix GPS data slow sensor refresh issue Fix GPS sensor update throttling for device tracking Nov 18, 2025
Copilot AI requested a review from JOHLC November 18, 2025 14:36
@JOHLC

JOHLC commented Nov 18, 2025

Copy link
Copy Markdown
Owner

@copilot, did you see the other comment? It seems to be flopping back to prev. values as well. Immediately after updating.

- Changed GPS sensor comparison from _last_reported_value to _attr_native_value
- This matches the flip-flop prevention used for non-GPS sensors
- Prevents GPS values from reverting to previous values immediately after updating

Co-authored-by: JOHLC <[email protected]>

Copilot AI commented Nov 18, 2025

Copy link
Copy Markdown
Contributor Author

@copilot, did you see the other comment? It seems to be flopping back to prev. values as well. Immediately after updating.

Fixed in commit e66a5c4. GPS sensors were experiencing flip-flopping due to comparing against _last_reported_value instead of _attr_native_value. Changed to match the flip-flop prevention logic used for non-GPS sensors (same fix from PR #21). This prevents GPS values from reverting to previous values immediately after updating.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants