MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / get_cached_wifi_networks

Method get_cached_wifi_networks

db_manager.py:1513–1551  ·  view source on GitHub ↗

Get cached WiFi networks scanned within the specified time window. Args: max_age_seconds: Maximum age of cached data (default: 5 minutes) Returns: List of network dicts

(self, max_age_seconds: int = 300)

Source from the content-addressed store, hash-verified

1511 network.get('security', ''),
1512 timestamp,
1513 1 if network.get('known', False) else 0,
1514 1 if network.get('has_system_profile', False) else 0
1515 ))
1516
1517 conn.commit()
1518 logger.debug(f"Cached {len([n for n in networks if not n.get('instruction')])} WiFi networks")
1519
1520 except Exception as e:
1521 logger.error(f"Error caching WiFi scan: {e}")
1522
1523 def get_cached_wifi_networks(self, max_age_seconds: int = 300) -> List[Dict[str, Any]]:
1524 """
1525 Get cached WiFi networks scanned within the specified time window.
1526
1527 Args:
1528 max_age_seconds: Maximum age of cached data (default: 5 minutes)
1529
1530 Returns:
1531 List of network dicts
1532 """
1533 try:
1534 with self.get_connection() as conn:
1535 cursor = conn.cursor()
1536 cutoff_time = datetime.now() - timedelta(seconds=max_age_seconds)
1537
1538 cursor.execute("""
1539 SELECT ssid, signal, security, last_seen, is_known, has_system_profile
1540 FROM wifi_scan_cache
1541 WHERE last_seen >= ?
1542 ORDER BY signal DESC
1543 """, (cutoff_time,))
1544
1545 networks = []
1546 for row in cursor.fetchall():
1547 networks.append({
1548 'ssid': row[0],
1549 'signal': row[1],
1550 'security': row[2],
1551 'last_seen': row[3],
1552 'known': bool(row[4]),
1553 'has_system_profile': bool(row[5])
1554 })

Callers

nothing calls this directly

Calls 7

get_connectionMethod · 0.95
cursorMethod · 0.80
appendMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80
executeMethod · 0.45
fetchallMethod · 0.45

Tested by

no test coverage detected