From eaf4553299f41fb1759f49232943b2d42a42c08f Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 9 Oct 2023 15:44:34 -0600 Subject: [PATCH] Limiting attempts to start the hotspot. --- wrolpi/admin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wrolpi/admin.py b/wrolpi/admin.py index 44ee656a..dcf11e64 100644 --- a/wrolpi/admin.py +++ b/wrolpi/admin.py @@ -45,18 +45,21 @@ def hotspot_status() -> HotspotStatus: return HotspotStatus.unknown -def enable_hotspot(): +def enable_hotspot(depth: int = 10): """Turn the Wi-Fi interface into a hotspot. If Wi-Fi is already running, replace that with a hotspot. """ + if depth < 0: + raise RuntimeError(f'Failed to start hotspot!') + status = hotspot_status() logger.info(f'Hotspot status: {status}') if status == HotspotStatus.connected: logger.info('Hotspot already connected. Rebooting hotspot.') disable_hotspot() - return enable_hotspot() + return enable_hotspot(depth=depth - 1) elif status == HotspotStatus.disconnected: # Radio is on, but not connected. Good, turn it into a hotspot. cmd = (SUDO_BIN, NMCLI_BIN, 'device', 'wifi', 'hotspot', 'ifname', WROLPI_CONFIG.hotspot_device, @@ -69,7 +72,7 @@ def enable_hotspot(): cmd = (SUDO_BIN, NMCLI_BIN, 'radio', 'wifi', 'on') subprocess.check_call(cmd) logger.info('Turned on hotspot radio.') - return enable_hotspot() + return enable_hotspot(depth=depth - 1) elif status == HotspotStatus.unknown: logger.error('Cannot enable hotspot with unknown status!')