BE: linting fixes 2

Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
jokob-sk
2025-11-22 20:43:36 +11:00
parent 5c14b34a8b
commit ebeb7a07af
63 changed files with 124 additions and 113 deletions

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
# Just a testing library plugin for development purposes
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import json
import subprocess

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys
import re

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import json
import os

View File

@@ -1,5 +1,5 @@
# !/usr/bin/env python
#!/usr/bin/env python
import json
import os

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python3
#!/usr/bin/env python3
import conf
from const import confFileName, logPath
from pytz import timezone

View File

@@ -1,5 +1,5 @@
# !/usr/bin/env python
#!/usr/bin/env python
import json
import os

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import subprocess
import os

View File

@@ -1,5 +1,5 @@
# !/usr/bin/env python
#!/usr/bin/env python
import json
import subprocess

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import time
import argparse

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python3
#!/usr/bin/env python3
import os
import sys
import socket

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import argparse

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import argparse

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
from __future__ import unicode_literals
import argparse

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
# Based on the work of https://github.com/leiweibau/Pi.Alert
import subprocess

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys
import subprocess

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
# test script by running:
# tbc

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import time

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
# test script by running:
# tbc

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import argparse

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
# test script by running:
# tbc

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
__author__ = "ffsb"
__version__ = "0.1" # initial
__version__ = "0.2" # added logic to retry omada api call once as it seems to sometimes fail for some reasons, and error handling logic...
@@ -134,7 +134,7 @@ def callomada(myargs):
omada_output = ""
retries = 2
while omada_output == "" and retries > 1:
while omada_output == "" and retries > 0:
retries = retries - 1
try:
mf = io.StringIO()
@@ -183,51 +183,71 @@ def add_uplink(
sadevices_linksbymac,
port_byswitchmac_byclientmac,
):
# Ensure switch_mac exists in device_data_bymac
# Ensure switch exists
if switch_mac not in device_data_bymac:
mylog("none", [f"[{pluginName}] switch_mac '{switch_mac}' not found in device_data_bymac"])
return
# Ensure SWITCH_AP key exists in the dictionary
if SWITCH_AP not in device_data_bymac[switch_mac]:
mylog("none", [f"[{pluginName}] Missing key '{SWITCH_AP}' in device_data_bymac[{switch_mac}]"])
dev_switch = device_data_bymac[switch_mac]
# Ensure list is long enough to contain SWITCH_AP index
if len(dev_switch) <= SWITCH_AP:
mylog("none", [f"[{pluginName}] SWITCH_AP index {SWITCH_AP} missing in record for {switch_mac}"])
return
# Check if uplink should be added
if device_data_bymac[switch_mac][SWITCH_AP] in [None, "null"]:
device_data_bymac[switch_mac][SWITCH_AP] = uplink_mac
# Add uplink only if empty
if dev_switch[SWITCH_AP] in (None, "null"):
dev_switch[SWITCH_AP] = uplink_mac
# Ensure uplink_mac exists in device_data_bymac
# Validate uplink_mac exists
if uplink_mac not in device_data_bymac:
mylog("none", [f"[{pluginName}] uplink_mac '{uplink_mac}' not found in device_data_bymac"])
return
# Determine port to uplink
if (
device_data_bymac[switch_mac].get(TYPE) == "Switch" and device_data_bymac[uplink_mac].get(TYPE) == "Switch"
):
dev_uplink = device_data_bymac[uplink_mac]
# Get TYPE safely
switch_type = dev_switch[TYPE] if len(dev_switch) > TYPE else None
uplink_type = dev_uplink[TYPE] if len(dev_uplink) > TYPE else None
# Switch-to-switch link → use port mapping
if switch_type == "Switch" and uplink_type == "Switch":
port_to_uplink = port_byswitchmac_byclientmac.get(switch_mac, {}).get(uplink_mac)
if port_to_uplink is None:
mylog("none", [f"[{pluginName}] Missing port info for switch_mac '{switch_mac}' and uplink_mac '{uplink_mac}'"])
mylog("none", [
f"[{pluginName}] Missing port info for {switch_mac}{uplink_mac}"
])
return
else:
port_to_uplink = device_data_bymac[uplink_mac].get(PORT_SSID)
# Other device types → read PORT_SSID index
if len(dev_uplink) <= PORT_SSID:
mylog("none", [
f"[{pluginName}] PORT_SSID index missing for uplink {uplink_mac}"
])
return
port_to_uplink = dev_uplink[PORT_SSID]
# Assign port to switch_mac
device_data_bymac[switch_mac][PORT_SSID] = port_to_uplink
# Assign port to switch
if len(dev_switch) > PORT_SSID:
dev_switch[PORT_SSID] = port_to_uplink
else:
mylog("none", [
f"[{pluginName}] PORT_SSID index missing in switch {switch_mac}"
])
# Recursively add uplinks for linked devices
# Process children recursively
for link in sadevices_linksbymac.get(switch_mac, []):
if (
link in device_data_bymac and device_data_bymac[link].get(SWITCH_AP) in [None, "null"] and device_data_bymac[switch_mac].get(TYPE) == "Switch"
link in device_data_bymac and len(device_data_bymac[link]) > SWITCH_AP and device_data_bymac[link][SWITCH_AP] in (None, "null") and len(dev_switch) > TYPE
):
add_uplink(
switch_mac,
link,
device_data_bymac,
sadevices_linksbymac,
port_byswitchmac_byclientmac,
)
if dev_switch[TYPE] == "Switch":
add_uplink(
switch_mac,
link,
device_data_bymac,
sadevices_linksbymac,
port_byswitchmac_byclientmac,
)
# ----------------------------------------------

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
"""
This plugin imports devices and clients from Omada Controller using their OpenAPI.
@@ -296,7 +296,7 @@ class OmadaAPI:
OmadaHelper.verbose(f"{method} request error: {str(ex)}")
return OmadaHelper.response("error", f"{method} request failed to endpoint '{endpoint}' with error: {str(ex)}")
def authenticate(self) -> Dict[str, any]:
def authenticate(self) -> Dict[str, Any]:
"""Make an endpoint request to get access token."""
OmadaHelper.verbose("Starting authentication process")

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
"""
NetAlertX plugin: PIHOLEAPI
Imports devices from Pi-hole v6 API (Network endpoints) into NetAlertX plugin results.

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
from __future__ import unicode_literals
import subprocess

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
# Inspired by https://github.com/stevehoek/Pi.Alert
from __future__ import unicode_literals

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
# Based on the work of https://github.com/leiweibau/Pi.Alert
import requests