Check for any usable network link, preferring Ethernet when present.
(self)
| 1259 | # Get both Ragnar's known networks AND system profiles |
| 1260 | ragnar_known = [net['ssid'] for net in self.known_networks] |
| 1261 | system_profiles = self.get_system_wifi_profiles() |
| 1262 | all_known = list(set(ragnar_known + system_profiles)) # Combine and deduplicate |
| 1263 | |
| 1264 | # Recorded so AP monitoring can tell "nothing to rejoin" apart from |
| 1265 | # "something to rejoin, just not in range right now". |
| 1266 | self.known_networks_count = len(all_known) |
| 1267 | if not all_known: |
| 1268 | return False |
| 1269 | |
| 1270 | # Strategy 1: Use secondary adapter for a reliable nmcli scan |
| 1271 | secondary = self._find_secondary_wifi_interface() |
| 1272 | if secondary: |
| 1273 | try: |
| 1274 | subprocess.run( |
| 1275 | ['nmcli', 'dev', 'wifi', 'rescan', 'ifname', secondary], |
| 1276 | capture_output=True, text=True, timeout=15 |
| 1277 | ) |
| 1278 | time.sleep(1) |
| 1279 | result = subprocess.run( |
| 1280 | ['nmcli', '-t', '-f', 'SSID', 'dev', 'wifi', 'list', 'ifname', secondary], |
| 1281 | capture_output=True, text=True, timeout=15 |
| 1282 | ) |
| 1283 | if result.returncode == 0: |
| 1284 | available_ssids = [ |
| 1285 | line.strip() for line in result.stdout.strip().split('\n') |
| 1286 | if line.strip() |
| 1287 | ] |
| 1288 | # Any result at all proves the scan path works here, so |
| 1289 | # "found nothing" can be trusted as genuinely nothing. |
| 1290 | if available_ssids: |
| 1291 | self.last_successful_scan = time.time() |
| 1292 | for known_ssid in all_known: |
| 1293 | if known_ssid in available_ssids: |
| 1294 | self.logger.info(f"Known network '{known_ssid}' detected via secondary adapter {secondary}") |
| 1295 | return True |
| 1296 | except Exception as e: |
| 1297 | self.logger.debug(f"Secondary adapter scan failed during known-network check: {e}") |
| 1298 |
no test coverage detected