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 @@ + +