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

Fix for ros 7.13 wireless #332

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Changes from 1 commit
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
63 changes: 55 additions & 8 deletions custom_components/mikrotik_router/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,16 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry):
self.host_tracking_initialized = False

self.support_capsman = False
self.support_wifi = False
self.support_wireless = False
self.support_wifiwave2 = False
self.support_ppp = False
self.support_ups = False
self.support_gps = False
self._wifimodule = None
tomaae marked this conversation as resolved.
Show resolved Hide resolved

self.major_fw_version = 0
self.minor_fw_version = 0

self.async_mac_lookup = AsyncMacLookup()
self.accessrights_reported = False
Expand Down Expand Up @@ -517,10 +520,37 @@ def get_capabilities(self):
self.support_wireless = True
slackr31337 marked this conversation as resolved.
Show resolved Hide resolved
if "wifiwave2" in packages and packages["wifiwave2"]["enabled"]:
self.support_wifiwave2 = True
self.support_wifi = False
self.support_capsman = False
self._wifimodule = "wifiwave2"

elif "wifi" in packages and packages["wifi"]["enabled"]:
self.support_wifiwave2 = False
tomaae marked this conversation as resolved.
Show resolved Hide resolved
self.support_wifi = True
self.support_capsman = False
self._wifimodule = "wifi"

elif "wifi-qcom" in packages and packages["wifi-qcom"]["enabled"]:
self.support_wifiwave2 = False
self.support_wifi = True
self.support_capsman = False
self._wifimodule = "wifi"

elif "wifi-qcom-ac" in packages and packages["wifi-qcom-ac"]["enabled"]:
self.support_wifiwave2 = False
self.support_wifi = True
self.support_capsman = False
self._wifimodule = "wifi"

else:
self.support_wifiwave2 = False
self.support_wifi = False
self.support_capsman = True

_LOGGER.debug("Mikrotik %s wifi module=%s",
self.host,
self._wifimodule,
)

if "ups" in packages and packages["ups"]["enabled"]:
self.support_ups = True
Expand Down Expand Up @@ -1553,14 +1583,23 @@ def get_firmware_update(self) -> None:

if self.ds["fw-update"]["installed-version"] != "unknown":
try:
self.major_fw_version = int(
tomaae marked this conversation as resolved.
Show resolved Hide resolved
self.ds["fw-update"].get("installed-version").split(".")[0]
full_version = self.ds["fw-update"].get("installed-version")
split_end = min(len(full_version),4)
version = re.sub("[^0-9\.]", "", full_version[0:split_end])
self.major_fw_version = int(version.split(".")[0])
self.minor_fw_version = int(version.split(".")[1])
_LOGGER.debug(
"Mikrotik %s FW version major=%s minor=%s (%s)",
self.host,
self.major_fw_version,
self.minor_fw_version,
full_version
)
except Exception:
_LOGGER.error(
"Mikrotik %s unable to determine major FW version (%s).",
self.host,
self.ds["fw-update"].get("installed-version"),
full_version,
)

# ---------------------------
Expand Down Expand Up @@ -1952,9 +1991,18 @@ def get_dhcp_network(self) -> None:
# ---------------------------
def get_capsman_hosts(self) -> None:
"""Get CAPS-MAN hosts data from Mikrotik"""

if self.major_fw_version >= 7 and self.minor_fw_version > 12:
registration_path = "/interface/wifi/registration-table"
self._wifimodule = "wifi"

else:
registration_path= "/caps-man/registration-table"
self._wifimodule = "wireless"

self.ds["capsman_hosts"] = parse_api(
data={},
source=self.api.query("/caps-man/registration-table"),
source=self.api.query(registration_path),
tomaae marked this conversation as resolved.
Show resolved Hide resolved
key="mac-address",
vals=[
{"name": "mac-address"},
Expand All @@ -1968,10 +2016,10 @@ def get_capsman_hosts(self) -> None:
# ---------------------------
def get_wireless(self) -> None:
"""Get wireless data from Mikrotik"""
wifimodule = "wifiwave2" if self.support_wifiwave2 else "wireless"

self.ds["wireless"] = parse_api(
data=self.ds["wireless"],
source=self.api.query(f"/interface/{wifimodule}"),
source=self.api.query(f"/interface/{self._wifimodule}"),
key="name",
vals=[
{"name": "master-interface", "default": ""},
Expand Down Expand Up @@ -2018,10 +2066,9 @@ def get_wireless(self) -> None:
# ---------------------------
def get_wireless_hosts(self) -> None:
"""Get wireless hosts data from Mikrotik"""
wifimodule = "wifiwave2" if self.support_wifiwave2 else "wireless"
self.ds["wireless_hosts"] = parse_api(
data={},
source=self.api.query(f"/interface/{wifimodule}/registration-table"),
source=self.api.query(f"/interface/{self._wifimodule}/registration-table"),
key="mac-address",
vals=[
{"name": "mac-address"},
Expand Down