style: ruff format and the lint rules of the driver standard

Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM
driver uses (E, F, I, UP, B at line length 100, Python 3.10). What ruff
cannot fix comes in the next commit.
This commit is contained in:
Christian Manivong committed 2026-10-23 08:32:47 +02:00
1 parent 7f2ae6ac58
commit a212bc8715
14 files changed
+322 -239

No files matched your search

+56 -35
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -101,8 +100,12 @@ class OpenWrtWirelessMixin:
return ""
_ENC_MAP = {
"": "Open", "none": "Open", "0": "Open",
"wep": "WEP", "wep-open": "WEP (Open)", "wep-shared": "WEP (Shared)",
"": "Open",
"none": "Open",
"0": "Open",
"wep": "WEP",
"wep-open": "WEP (Open)",
"wep-shared": "WEP (Shared)",
"psk": "WPA-PSK",
"psk+ccmp": "WPA-PSK",
"psk-mixed": "WPA/WPA2-PSK",
@@ -176,11 +179,17 @@ class OpenWrtWirelessMixin:
ft_over_ds = entry.get("ft_over_ds", "1") == "1"
client_isolation = entry.get("isolate", "0") == "1"
_max_raw = entry.get("maxassoc")
max_clients: int | None = int(_max_raw) if _max_raw and str(_max_raw).isdigit() else None
max_clients: int | None = (
int(_max_raw) if _max_raw and str(_max_raw).isdigit() else None
)
_disassoc_raw = entry.get("disassoc_low_ack")
disassoc_low_ack: bool | None = (_disassoc_raw == "1") if _disassoc_raw is not None else None
disassoc_low_ack: bool | None = (
(_disassoc_raw == "1") if _disassoc_raw is not None else None
)
_max_inact_raw = entry.get("max_inactivity")
max_inactivity: int | None = int(_max_inact_raw) if _max_inact_raw and str(_max_inact_raw).isdigit() else None
max_inactivity: int | None = (
int(_max_inact_raw) if _max_inact_raw and str(_max_inact_raw).isdigit() else None
)
key: str = entry.get("key", "") or ""
acl_mode = _ACL_MODE_MAP.get(entry.get("macfilter", ""), "off")
mac_list = sorted(set(iface_maclists.get(idx, [])))
@@ -331,16 +340,18 @@ class OpenWrtWirelessMixin:
def _flush() -> None:
if current_station and current_station.get("mac"):
info = ap_ifaces.get(active_iface, {})
results.append(WirelessClientDict(
mac=current_station["mac"],
ssid=info.get("ssid", ""),
radio=info.get("band") or info.get("radio", ""),
signal=current_station.get("signal", 0),
noise=0,
tx_rate=current_station.get("tx_rate", 0.0),
rx_rate=current_station.get("rx_rate", 0.0),
uptime=current_station.get("uptime", 0),
))
results.append(
WirelessClientDict(
mac=current_station["mac"],
ssid=info.get("ssid", ""),
radio=info.get("band") or info.get("radio", ""),
signal=current_station.get("signal", 0),
noise=0,
tx_rate=current_station.get("tx_rate", 0.0),
rx_rate=current_station.get("rx_rate", 0.0),
uptime=current_station.get("uptime", 0),
)
)
for line in station_out.splitlines():
stripped = line.strip()
@@ -410,7 +421,6 @@ class OpenWrtWirelessMixin:
Keys are interface names (e.g. ``"wlan0"``). Values are lists of
:class:`~napalm_device_types.models.ChannelScanEntryDict`.
"""
from napalm_device_types.models import ChannelScanEntryDict
# Step 1: discover interfaces and filter to AP mode only
iw_out = self._send_command("iw dev 2>/dev/null || true")
@@ -435,10 +445,7 @@ class OpenWrtWirelessMixin:
if current_iface:
iface_order.append((current_iface, current_type))
ap_ifaces = [
name for name, itype in iface_order
if itype.upper() in ("AP", "AP/VLAN")
]
ap_ifaces = [name for name, itype in iface_order if itype.upper() in ("AP", "AP/VLAN")]
if not ap_ifaces:
return {}
@@ -489,15 +496,17 @@ class OpenWrtWirelessMixin:
# If width is still 0 try to derive from HT/VHT/HE info
if width == 0 and current.get("_ht_width"):
width = current["_ht_width"]
entries.append(ChannelScanEntryDict(
bssid=current["bssid"],
ssid=current.get("ssid", ""),
frequency=freq,
channel=ch,
signal_dbm=current.get("signal_dbm", 0),
channel_width=width,
band=_freq_to_band(freq),
))
entries.append(
ChannelScanEntryDict(
bssid=current["bssid"],
ssid=current.get("ssid", ""),
frequency=freq,
channel=ch,
signal_dbm=current.get("signal_dbm", 0),
channel_width=width,
band=_freq_to_band(freq),
)
)
for line in scan_out.splitlines():
stripped = line.strip()
@@ -663,10 +672,22 @@ class OpenWrtWirelessMixin:
# Derive channel_width from htmode string (e.g. VHT80 → 80 MHz)
_HTMODE_WIDTH = {
"HT20": 20, "HT40": 40,
"VHT20": 20, "VHT40": 40, "VHT80": 80, "VHT80+80": 80, "VHT160": 160,
"HE20": 20, "HE40": 40, "HE80": 80, "HE160": 160,
"EHT20": 20, "EHT40": 40, "EHT80": 80, "EHT160": 160, "EHT320": 320,
"HT20": 20,
"HT40": 40,
"VHT20": 20,
"VHT40": 40,
"VHT80": 80,
"VHT80+80": 80,
"VHT160": 160,
"HE20": 20,
"HE40": 40,
"HE80": 80,
"HE160": 160,
"EHT20": 20,
"EHT40": 40,
"EHT80": 80,
"EHT160": 160,
"EHT320": 320,
}
channel_width = _HTMODE_WIDTH.get(htmode.upper(), 0)
@@ -677,7 +698,7 @@ class OpenWrtWirelessMixin:
channel=channel,
channel_width=channel_width,
tx_power=tx_power,
frequency=0.0, # enriched below via iwinfo
frequency=0.0, # enriched below via iwinfo
),
"htmode": htmode,
"country": country,