diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..c73e032 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,23 @@ +name: Pylint + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + - name: Analysing the code with pylint + run: | + pylint $(git ls-files '*.py') diff --git a/technicolorgateway/__init__.py b/technicolorgateway/__init__.py index 995aaaa..d2563fa 100644 --- a/technicolorgateway/__init__.py +++ b/technicolorgateway/__init__.py @@ -7,7 +7,12 @@ from robobrowser import RoboBrowser from technicolorgateway import mysrp as srp -from technicolorgateway.modal import get_device_modal, get_broadband_modal +from technicolorgateway.modal import ( + get_device_modal, + get_broadband_modal, + get_system_info_modal, + get_diagnostics_connection_modal, +) _LOGGER = logging.getLogger(__name__) @@ -98,3 +103,39 @@ def get_broadband_modal(self): self._br._update_state(req) content = req.content.decode() return get_broadband_modal(content) + + def get_system_info_modal(self): + """Open System info modal and return the properties as a dict. Depending + on your hardware model, this may include the following keys: + "Product Vendor", + "Product Name", + "Serial Number", + "Software Version", + "Uptime since last reboot", + "Firmware Version", + "Hardware Version", + "MAC Address", + "Memory Usage", + "CPU Usage", + "Reboot Cause", + """ + req = self._br.session.get(f"{self._uri}/modals/system-info-modal.lp") + self._br._update_state(req) + content = req.content.decode() + return get_system_info_modal(content) + + def get_diagnostics_connection_modal(self): + """Open Diagnostics Connection modal and return connection check as a + dict. Depending on your hardware model, this may include the following + keys: + 'WAN Enable', 'WAN Available', 'IP Version 4 Address', 'IP Version 6 + Address', 'Next Hop Ping', 'First DNS Server Ping', 'Second DNS + Server Ping' + """ + + req = self._br.session.get( + f"{self._uri}/modals/diagnostics-connection-modal.lp" + ) + self._br._update_state(req) + content = req.content.decode() + return get_diagnostics_connection_modal(content) diff --git a/technicolorgateway/modal.py b/technicolorgateway/modal.py index 4aeef10..778a9fd 100644 --- a/technicolorgateway/modal.py +++ b/technicolorgateway/modal.py @@ -70,3 +70,30 @@ def get_data_from_rows(data, rows): cols = row.find_all('td') cols = [ele.text.strip() for ele in cols] data.append({'name': cols[name_index], 'ip': cols[ip_index], 'mac': cols[mac_index]}) + +def get_system_info_modal(content): + soup = BeautifulSoup(content, "html.parser") + # Extract product information + product_info = {} + for div in soup.select("div.control-group"): + label = div.select_one("label.control-label") + span = div.select_one("span.simple-desc") + if label and span: + key = label.text.strip() + value = span.text.strip() + product_info[key] = value + return product_info + + +def get_diagnostics_connection_modal(content): + soup = BeautifulSoup(content, "html.parser") + # Extract connection diagnostics + product_info = {} + for div in soup.select("div.control-group"): + label = div.select_one("label.control-label") + span = div.select_one("span.simple-desc") + if label and span: + key = label.text.strip() + value = span.text.strip() + product_info[key] = value + return product_info diff --git a/tests/resources/diagnostics-connection-modal.lp b/tests/resources/diagnostics-connection-modal.lp new file mode 100644 index 0000000..6dcdc6e --- /dev/null +++ b/tests/resources/diagnostics-connection-modal.lp @@ -0,0 +1,122 @@ + + + + + + + diff --git a/tests/resources/system-info-modal.lp b/tests/resources/system-info-modal.lp new file mode 100644 index 0000000..6b53a5e --- /dev/null +++ b/tests/resources/system-info-modal.lp @@ -0,0 +1,136 @@ + + + + + diff --git a/tests/test_modal.py b/tests/test_modal.py index a96eaf8..5eb794b 100644 --- a/tests/test_modal.py +++ b/tests/test_modal.py @@ -1,4 +1,9 @@ -from technicolorgateway.modal import get_broadband_modal, get_device_modal +from technicolorgateway.modal import ( + get_broadband_modal, + get_device_modal, + get_system_info_modal, + get_diagnostics_connection_modal, +) class TestModal: @@ -97,3 +102,43 @@ def test_get_device_modal_052823(self): assert modal_list[0]['name'] == 'EdgeRouter-X' assert modal_list[0]['ip'] == '192.168.0.152' assert modal_list[0]['mac'] == '74:83:c2:fd:e0:07' + + def test_get_system_info_modal(self): + with open("tests/resources/system-info-modal.lp", encoding="utf-8") as file: + content = file.read() + modal_dict = get_system_info_modal(content) + print("\n") + print(modal_dict) + assert len(modal_dict) == 11 + assert modal_dict["Product Vendor"] == "Technicolor" + assert modal_dict["Product Name"] == "Telia F1" + assert modal_dict["Serial Number"] == "CP2221ADU9K" + assert modal_dict["Software Version"] == "19.5" + assert ( + modal_dict["Uptime since last reboot"] + == "19 days 6 hours 13 minutes 8 seconds" + ) + assert modal_dict["Firmware Version"] == "19.5.1062-4581003" + assert modal_dict["Hardware Version"] == "GCNT-X" + assert modal_dict["MAC Address"] == "AA:BB:CC:45:18:0E" + assert modal_dict["Memory Usage"] == "86 %" + assert modal_dict["CPU Usage"] == "2 %" + assert modal_dict["Reboot Cause"] == "Power" + + def test_get_diagnostics_connection_modal(self): + with open( + "tests/resources/diagnostics-connection-modal.lp", encoding="utf-8" + ) as file: + content = file.read() + modal_dict = get_diagnostics_connection_modal(content) + print("\n") + print(modal_dict) + assert len(modal_dict) == 7 + + assert modal_dict["WAN Enable"] == "Interface Enabled" + assert modal_dict["WAN Available"] == "Link Up" + assert modal_dict["IP Version 4 Address"] == "82.133.131.13" + assert modal_dict["IP Version 6 Address"] == "No Address Assigned" + assert modal_dict["Next Hop Ping"] == "Success" + assert modal_dict["First DNS Server Ping"] == "Success" + assert modal_dict["Second DNS Server Ping"] == "Success"