Skip to content

Commit 4d70e96

Browse files
wip
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
1 parent 2171730 commit 4d70e96

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

core/services/wifi/wifi_handlers/networkmanager/networkmanager.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,40 +116,29 @@ async def start(self) -> None:
116116
# Find WiFi device
117117
assert self._nm is not None
118118
devices = await self._nm.get_devices()
119-
120-
# First, try to use configured interface if set
121-
configured_interface = self._settings_manager.settings.primary_interface
122-
if configured_interface:
123-
for device_path in devices:
124-
device = NetworkDeviceWireless(device_path, self._bus)
125-
if await device.device_type == DeviceType.WIFI:
126-
if await device.interface == configured_interface:
127-
self._device_path = device_path
128-
logger.info(f"Using configured WiFi interface: {configured_interface}")
129-
break
130-
131-
# Fallback to first available WiFi device
132-
if not self._device_path:
133-
for device_path in devices:
134-
device = NetworkDeviceWireless(device_path, self._bus)
135-
if await device.device_type == DeviceType.WIFI:
136-
self._device_path = device_path
137-
break
119+
for device_path in devices:
120+
device = NetworkDeviceWireless(device_path, self._bus)
121+
if await device.device_type == DeviceType.WIFI:
122+
self._device_path = device_path
123+
break
138124

139125
# Create virtual AP interface if needed
140126
await self._create_virtual_interface()
141127
self._tasks.append(asyncio.get_event_loop().create_task(self._autoscan()))
142128
self._tasks.append(asyncio.get_event_loop().create_task(self.hotspot_watchdog()))
143129

144130
async def _get_wifi_devices(self) -> List[tuple[str, str]]:
145-
"""Get all WiFi devices as (device_path, interface_name) tuples."""
131+
"""Get all WiFi devices as (device_path, interface_name) tuples, excluding virtual AP interfaces."""
146132
assert self._nm is not None
147133
wifi_devices: List[tuple[str, str]] = []
148134
devices = await self._nm.get_devices()
149135
for device_path in devices:
150136
device = NetworkDeviceWireless(device_path, self._bus)
151137
if await device.device_type == DeviceType.WIFI:
152138
interface_name = await device.interface
139+
# Skip virtual AP interface used for hotspot
140+
if interface_name == self._ap_interface:
141+
continue
153142
wifi_devices.append((device_path, interface_name))
154143
return wifi_devices
155144

@@ -166,13 +155,28 @@ async def _select_wifi_device(self) -> None:
166155
if interface_name == configured_interface:
167156
self._device_path = device_path
168157
logger.info(f"Using configured WiFi interface: {configured_interface}")
158+
# Trigger a scan on the newly selected device
159+
await self._request_scan()
169160
return
170161

171162
logger.warning(f"Configured interface {configured_interface} not found, using first available")
172163

173164
# Use first available device
174165
self._device_path = wifi_devices[0][0]
175166
logger.info(f"Using WiFi interface: {wifi_devices[0][1]}")
167+
# Trigger a scan on the newly selected device
168+
await self._request_scan()
169+
170+
async def _request_scan(self) -> None:
171+
"""Request a WiFi scan on the current device."""
172+
if not self._device_path:
173+
return
174+
try:
175+
device = NetworkDeviceWireless(self._device_path, self._bus)
176+
await device.request_scan({})
177+
logger.info("Requested WiFi scan on new interface")
178+
except Exception as e:
179+
logger.warning(f"Failed to request scan: {e}")
176180

177181
async def _autoscan(self) -> None:
178182

@@ -274,16 +278,11 @@ async def wait_for_connection(timeout: int = 30) -> bool:
274278
return
275279

276280
# If no existing connection, create a new one
277-
# Get the interface name from the current device
278-
assert self._device_path is not None
279-
current_device = NetworkDeviceWireless(self._device_path, self._bus)
280-
interface_name = await current_device.interface
281-
282281
connection: dict[str, dict[str, tuple[str, Any]]] = {
283282
"connection": {
284283
"type": ("s", "802-11-wireless"),
285284
"id": ("s", credentials.ssid),
286-
"interface-name": ("s", interface_name),
285+
"interface-name": ("s", "wlan0"),
287286
"autoconnect": ("b", True),
288287
},
289288
"802-11-wireless": {

0 commit comments

Comments
 (0)