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

Method render_wifi_wave_indicator

display.py:538–575  ·  view source on GitHub ↗

Render a live Wi-Fi indicator using wave arcs with no dBm text.

(self, image, draw)

Source from the content-addressed store, hash-verified

536 # # # return bool(output.strip())
537 # # # except Exception as e:
538 # # # logger.error(f"Error checking Bluetooth connection status: {e}")
539 # # # return False
540
541 def is_wifi_connected(self):
542 """Check if WiFi is connected by checking the current SSID and network connectivity."""
543 try:
544 # Method 1: Try iwgetid first
545 result = subprocess.Popen(['iwgetid', '-r'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
546 ssid, error = result.communicate()
547 if result.returncode == 0 and ssid.strip():
548 logger.debug(f"WiFi connected via iwgetid: SSID={ssid.strip()}")
549 return True
550
551 # Method 2: Check if we have an active network interface with IP
552 result = subprocess.Popen(['ip', 'route', 'get', '8.8.8.8'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
553 route_output, error = result.communicate()
554 if result.returncode == 0 and 'via' in route_output:
555 logger.debug(f"WiFi connected via ip route check")
556 return True
557
558 # Method 3: Check for wlan interface with IP
559 result = subprocess.Popen(['ip', 'addr', 'show'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
560 addr_output, error = result.communicate()
561 if result.returncode == 0:
562 # Look for wlan interfaces with inet addresses
563 for line in addr_output.split('\n'):
564 if ('wlan' in line and 'state UP' in line) or ('inet ' in line and 'scope global' in line and ('wlan' in addr_output)):
565 logger.debug(f"WiFi connected via interface check")
566 return True
567
568 logger.debug(f"WiFi not detected by any method")
569 return False
570
571 except Exception as e:
572 logger.error(f"Error checking WiFi status: {e}")
573 return False
574
575 def _dbm_to_quality(self, signal_dbm):
576 """Convert RSSI (dBm) to an approximate 0-100 quality percentage."""
577 if signal_dbm is None:
578 return None

Callers 1

runMethod · 0.95

Calls 4

_dbm_to_qualityMethod · 0.95
get_wifi_wave_countMethod · 0.95
rangeFunction · 0.85

Tested by

no test coverage detected