Reset Wi-Fi state on radio changes and daemon startup

This commit is contained in:
Adeeb Shihadeh
2026-10-20 10:39:13 -07:00
parent f594ae7076
commit 7196caaede
2 changed files with 16 additions and 3 deletions
+12
View File
@@ -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'
+4 -3
View File
@@ -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)