Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions custom_components/torque/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ def _parse_sensor_data(
if pid is not None:
if pid in self.sensors:
try:
# Add debug logging for GPS sensors
if pid in GPS_PIDS:
_LOGGER.debug(
"Received GPS data for PID %d (%s): %s",
pid,
self.sensors[pid]._attr_name,
value,
)
self.sensors[pid].async_on_update(value)
except Exception as exc:
_LOGGER.error("Error updating sensor for PID %d: %s", pid, exc)
Expand Down Expand Up @@ -688,11 +696,18 @@ def async_on_update(self, value: str) -> None:

# GPS sensors bypass throttling and debouncing for real-time tracking
if self._is_gps_sensor():
# Check if change is significant (use smaller threshold for GPS)
if (
self._last_reported_value is None
or abs(new_value - self._last_reported_value) >= 0.00001
):
# Always update GPS sensors - track every position change for device tracking
# GPS coordinates should be updated even if the value is identical to enable
# proper device tracking and location history in Home Assistant
# Check against current state to prevent flip-flopping (same as non-GPS fix)
if self._attr_native_value is None or new_value != self._attr_native_value:
_LOGGER.debug(
"GPS sensor %s (PID %d) updating: %s -> %s",
self._attr_name,
self._pid,
self._attr_native_value,
new_value,
)
self._attr_native_value = new_value
self._last_reported_value = new_value
self._last_update = now
Expand Down
4 changes: 4 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ def test_gps_sensor_high_precision_updates(self):
sensor.async_on_update("-77.921620000")
assert sensor.native_value == -77.92162

# Even identical values should update (for location tracking history)
sensor.async_on_update("-77.921620000")
assert sensor.native_value == -77.92162

def test_non_gps_sensor_still_throttled(self):
"""Test that non-GPS sensors still use throttling."""
from unittest.mock import patch
Expand Down