Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for getting system information. #28

Merged
merged 2 commits into from
May 1, 2021
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
47 changes: 47 additions & 0 deletions compal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import io
import itertools
import logging
import re
import time
import urllib
from collections import OrderedDict
from datetime import timedelta
from enum import Enum
from xml.dom import minidom

Expand All @@ -24,6 +26,7 @@
PortForward,
Proto,
RadioSettings,
SystemInfo,
TimerMode,
)

Expand Down Expand Up @@ -228,6 +231,50 @@ def parse_response(text):

return res

def system_info(self):
"""
Get system information
"""
system_info = SystemInfo()

parser = etree.XMLParser(recover=True)
res = self.xml_getter(GetFunction.CM_SYSTEM_INFO, {})
xml = etree.fromstring(res.content, parser=parser)

cm_docsis_mode = xml.find("cm_docsis_mode")
if cm_docsis_mode is not None:
system_info.docsis_mode = cm_docsis_mode.text

cm_hardware_version = xml.find("cm_hardware_version")
if cm_hardware_version is not None:
system_info.hardware_version = cm_hardware_version.text

cm_mac_addr = xml.find("cm_mac_addr")
if cm_mac_addr is not None:
system_info.mac_address = cm_mac_addr.text

cm_serial_number = xml.find("cm_serial_number")
if cm_serial_number is not None:
system_info.serial_number = cm_serial_number.text

cm_system_uptime = xml.find("cm_system_uptime")
if cm_system_uptime is not None:
match = re.match(
r"^(\d+)day(?:\(s\))?(\d+)h?\:(\d+)m?\:(\d+)s?$", cm_system_uptime.text
)
system_info.uptime = timedelta(
days=int(match[1]),
hours=int(match[2]),
minutes=int(match[3]),
seconds=int(match[4]),
)

cm_network_access = xml.find("cm_network_access")
if cm_network_access is not None:
system_info.network_access = cm_network_access.text

return system_info

def reboot(self):
"""
Reboot the router
Expand Down
10 changes: 10 additions & 0 deletions compal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from typing import Optional, List


@dataclass
class SystemInfo:
docsis_mode: Optional[str] = None
hardware_version: Optional[str] = None
mac_address: Optional[str] = None
serial_number: Optional[str] = None
uptime: Optional[int] = None
network_access: Optional[str] = None


@dataclass
class BandSetting:
radio: Optional[int] = None
Expand Down