Skip to content

Commit

Permalink
Merge pull request #332 from slackr31337/ros-7.13
Browse files Browse the repository at this point in the history
Fix for ros 7.13 wireless
  • Loading branch information
tomaae authored Feb 14, 2024
2 parents a61dfa5 + 6bc4415 commit 5feb9ad
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions custom_components/mikrotik_router/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,13 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry):

self.support_capsman = False
self.support_wireless = False
self.support_wifiwave2 = False
self.support_ppp = False
self.support_ups = False
self.support_gps = False
self._wifimodule = "wireless"

self.major_fw_version = 0
self.minor_fw_version = 0

self.async_mac_lookup = AsyncMacLookup()
self.accessrights_reported = False
Expand Down Expand Up @@ -516,11 +517,29 @@ def get_capabilities(self):
self.support_ppp = True
self.support_wireless = True
if "wifiwave2" in packages and packages["wifiwave2"]["enabled"]:
self.support_wifiwave2 = True
self.support_capsman = False
self._wifimodule = "wifiwave2"

elif "wifi" in packages and packages["wifi"]["enabled"]:
self.support_capsman = False
self._wifimodule = "wifi"

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

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

else:
self.support_wifiwave2 = False
self.support_capsman = True
self.support_wireless = bool(self.minor_fw_version < 13)

_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 +1572,23 @@ def get_firmware_update(self) -> None:

if self.ds["fw-update"]["installed-version"] != "unknown":
try:
self.major_fw_version = int(
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 +1980,16 @@ 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"

else:
registration_path= "/caps-man/registration-table"

self.ds["capsman_hosts"] = parse_api(
data={},
source=self.api.query("/caps-man/registration-table"),
source=self.api.query(registration_path),
key="mac-address",
vals=[
{"name": "mac-address"},
Expand All @@ -1968,10 +2003,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 +2053,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

0 comments on commit 5feb9ad

Please sign in to comment.