fix: persist car-connected flag so trip building works across reboots (BUG-16)

connect_obd() set _car_ever_connected without a global declaration, so the
module-level flag was never set and was_car_ever_connected() always returned
False — local trip building has been silently blocked since BUG-10 landed.
Also persist the flag to the settings table so a drive followed by a reboot
still builds trips, and clean up dead code in was_car_ever_connected().
This commit is contained in:
Mathieu Moran
2026-08-13 15:41:30 -04:00
parent e0ae179c38
commit e5ac14e38b
2 changed files with 52 additions and 7 deletions
+30
View File
@@ -0,0 +1,30 @@
import unittest
from unittest.mock import patch
from modules import app_obd
class CarConnectedFlagTest(unittest.TestCase):
def setUp(self):
app_obd._car_ever_connected = False
def tearDown(self):
app_obd._car_ever_connected = False
def test_was_ever_connected_reads_persisted_flag(self):
with patch("modules.app_sql.get_setting", return_value="1"):
self.assertTrue(app_obd.was_car_ever_connected())
self.assertTrue(app_obd._car_ever_connected)
def test_was_ever_connected_defaults_false(self):
with patch("modules.app_sql.get_setting", return_value="0"):
self.assertFalse(app_obd.was_car_ever_connected())
def test_persist_car_connected_writes_setting(self):
with patch("modules.app_sql.set_setting") as mock_set:
app_obd._persist_car_connected()
mock_set.assert_called_once_with("car_ever_connected", "1")
if __name__ == "__main__":
unittest.main()