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

Method add_known_network

wifi_manager.py:2053–2075  ·  view source on GitHub ↗

Add a network to the known networks list

(self, ssid, password=None, priority=1)

Source from the content-addressed store, hash-verified

2051 profile_exists = check_result.returncode == 0
2052
2053 if profile_exists:
2054 self.logger.info(f"Found existing connection profile for {ssid}")
2055
2056 # If password is provided and profile exists, try to update the password
2057 if password:
2058 self.logger.info(f"Updating password for existing profile {ssid}")
2059 update_cmd = ['sudo', 'nmcli', 'con', 'modify', ssid, 'wifi-sec.psk', password]
2060 subprocess.run(update_cmd, capture_output=True, text=True)
2061
2062 # Try to activate the existing connection
2063 self.logger.info(f"Activating existing connection profile for {ssid}")
2064 cmd = ['sudo', 'nmcli', 'con', 'up', ssid]
2065 else:
2066 # No existing profile - create a new one
2067 self.logger.info(f"No existing profile found for {ssid}, creating new connection")
2068 cmd = ['sudo', 'nmcli', 'dev', 'wifi', 'connect', ssid]
2069 if password:
2070 cmd.extend(['password', password])
2071
2072 self.logger.info(f"Executing: {' '.join(cmd[:3])} {ssid} {'password ***' if password else ''}")
2073 result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
2074
2075 # Get signal strength if available
2076 signal_strength = None
2077 try:
2078 for net in self.available_networks:

Callers 1

connect_wifiFunction · 0.80

Calls 4

save_wifi_configMethod · 0.95
appendMethod · 0.80
infoMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected