Refactor Omada class methods for clarity; update device blocking logic in DeviceBlockAPIView and improve user verification error handling
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 3m14s

This commit is contained in:
2025-06-23 23:14:40 +05:00
parent 9688635f44
commit 570cf80019
4 changed files with 36 additions and 14 deletions

View File

@ -20,7 +20,7 @@ class Omada:
if not self.group_id:
raise ValueError("OMADA_GROUP_ID is not set in the environment variables.")
def get_existing_omada_devices(self):
def _get_existing_omada_devices(self):
"""
Get existing Omada devices from the database.
:return: List of existing device names.
@ -64,7 +64,7 @@ class Omada:
"portMaskList": None,
"domainNamePort": None,
}
existing_devices = self.get_existing_omada_devices()
existing_devices = self._get_existing_omada_devices()
PAYLOAD["macAddressList"] = existing_devices
print("Payload with existing devices: ", PAYLOAD)
for device in new_devices:
@ -91,3 +91,22 @@ class Omada:
print(f"Failed to add devices: {response.text}")
except requests.RequestException as e:
print(f"Error adding devices to Omada: {e}")
def block_device(self, mac_address: str, operation: str = "block"):
"""
Block a device in Omada.
:param mac_address: The MAC address of the device to block.
"""
try:
url = f"{self.proxy_url}/9fd0cffa3475a74ae4e4d37de0d12414/api/v2/sites/{self.site_id}/cmd/clients/{mac_address}/{operation}"
response = requests.post(
url,
headers={"X-API-Key": str(self.api_key)},
)
if response.status_code == 200:
data = response.json()
return data
else:
print(f"Failed to block device: {response.text}")
except requests.RequestException as e:
print(f"Error blocking device in Omada: {e}")