From 7196caaede6d9e82bee3d0e057131e6c4d8fa2ee Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 20 Oct 2026 10:39:13 -0700 Subject: [PATCH] Reset Wi-Fi state on radio changes and daemon startup --- tests/test_wifi.py | 12 ++++++++++++ userspace/root/usr/comma/wifi.py | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/test_wifi.py b/tests/test_wifi.py index f540d66..cb26d32 100644 --- a/tests/test_wifi.py +++ b/tests/test_wifi.py @@ -92,6 +92,18 @@ class TestWifi(unittest.TestCase): self.assertEqual(self.path.read_text(), before) self.assertEqual(self.wifi.data['hotspot']['password'], 'swagswagcomma') + def test_radio_reset_reloads_client_profiles(self): + self.wifi.pending = wifi.validate_network('B', 'password') + self.ctrl.commands.clear() + with patch.object(self.wifi, 'stop_hotspot'): + self.wifi.command('radio', enabled=False) + self.assertIsNone(self.wifi.pending) + self.assertIn('REMOVE_NETWORK all', self.ctrl.commands) + self.assertNotIn('ENABLE_NETWORK all', self.ctrl.commands) + self.wifi.command('radio', enabled=True) + self.assertIn('ENABLE_NETWORK all', self.ctrl.commands) + self.assertEqual(set(self.wifi.ids), {'A'}) + def test_scan_security_and_strength(self): self.ctrl.scan += '00:11:22:33:44:55\t2412\t-55\t[WPA2-PSK-CCMP][ESS]\tcaf\\xc3\\xa9\n' self.ctrl.scan += '00:11:22:33:44:66\t2412\t-75\t[WPA2-PSK-CCMP][ESS]\tcaf\\xc3\\xa9\n' diff --git a/userspace/root/usr/comma/wifi.py b/userspace/root/usr/comma/wifi.py index cbee06a..c8fc090 100755 --- a/userspace/root/usr/comma/wifi.py +++ b/userspace/root/usr/comma/wifi.py @@ -277,9 +277,9 @@ class Wifi: self.reload() elif command == 'radio': self.radio = bool(args['enabled']) - if not self.radio: - self.stop_hotspot() - self.ctrl.call('ENABLE_NETWORK all' if self.radio else 'DISABLE_NETWORK all') + self.pending = None + self.stop_hotspot() + self.reload() else: raise ValueError('unsupported Wi-Fi command') return {'ok': True} @@ -365,6 +365,7 @@ def main(): events = Supplicant() events.call('ATTACH') wifi = Wifi(ctrl) + wifi.stop_hotspot() # Clear leases/NAT left by a previous unclean daemon exit. server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) Path(SOCKET).unlink(missing_ok=True) server.bind(SOCKET)