Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions core/strategies/wifi/admin_panel_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import Any

import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from bs4 import BeautifulSoup

from core.strategies.wifi.base_wifi_strategy import BaseWiFiStrategy
Expand All @@ -23,6 +25,15 @@ def __init__(self, login_data: dict[str, Any]) -> None:
"""Constructor for AdminPanelStrategy."""
super().__init__()
self._login_data: dict[str, Any] = login_data
self._session: requests.Session = requests.Session()

# Create a HTTP adapter to limit the number of connections.
retries = Retry(total=3, backoff_factor=0.3, backoff_max=5.0)
http_adaptor: HTTPAdapter = HTTPAdapter(
pool_connections=1, max_retries=retries
)
self._session.mount("http://", http_adaptor)
self._session.mount("https://", http_adaptor)

def check_protectors(self) -> WiFiStrategyResult:
"""This method checks if there are any protectors around."""
Expand All @@ -38,9 +49,8 @@ def check_protectors(self) -> WiFiStrategyResult:
def _get_all_connected(self) -> list[ConnectedDeviceResult]:
"""This method returns a list of addresses of the clients connected to the network."""
# Create a session to store cookies.
session = requests.Session()
session.get("http://192.168.1.95/login_security.html")
session.post(
self._session.get("http://192.168.1.95/login_security.html")
self._session.post(
"http://192.168.1.95/Forms/login_security_1",
headers={
"Content-Type": "application/x-www-form-urlencoded",
Expand All @@ -50,7 +60,8 @@ def _get_all_connected(self) -> list[ConnectedDeviceResult]:
)

# Get the response for the page with MAC address list.
response = session.get("http://192.168.1.95/status/status_deviceinfo.htm")
response = self._session.get(
"http://192.168.1.95/status/status_deviceinfo.htm")

# Parse the response.
soup = BeautifulSoup(response.text, "html.parser")
Expand All @@ -62,7 +73,6 @@ def _get_all_connected(self) -> list[ConnectedDeviceResult]:
for element in tabdata
if len(element.text) == 17
]
session.close()

logger.debug("Connected devices: %s", str(mac_addrs))
return [ConnectedDeviceResult(mac_addr.upper()) for mac_addr in mac_addrs]
11 changes: 11 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
astroid==3.1.0
dill==0.3.8
flake8==7.0.0
Flake8-pyproject==1.2.3
isort==5.13.2
mccabe==0.7.0
platformdirs==4.2.1
pycodestyle==2.11.1
pyflakes==3.2.0
pylint==3.1.0
tomlkit==0.12.4