mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-07 16:04:29 +02:00
controller code cleanup
This commit is contained in:
parent
d1a8c624fb
commit
40d98f4778
1 changed files with 21 additions and 25 deletions
|
@ -1404,9 +1404,11 @@ class MikrotikControllerData:
|
||||||
else:
|
else:
|
||||||
self.data["resource"]["hdd-usage"] = "unknown"
|
self.data["resource"]["hdd-usage"] = "unknown"
|
||||||
|
|
||||||
if "uptime_epoch" in self.data["resource"]:
|
if (
|
||||||
if 0 < tmp_rebootcheck < self.data["resource"]["uptime_epoch"]:
|
"uptime_epoch" in self.data["resource"]
|
||||||
self.get_firmware_update()
|
and 0 < tmp_rebootcheck < self.data["resource"]["uptime_epoch"]
|
||||||
|
):
|
||||||
|
self.get_firmware_update()
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# get_firmware_update
|
# get_firmware_update
|
||||||
|
@ -1426,10 +1428,9 @@ class MikrotikControllerData:
|
||||||
|
|
||||||
if "status" in self.data["fw-update"]:
|
if "status" in self.data["fw-update"]:
|
||||||
self.data["fw-update"]["available"] = (
|
self.data["fw-update"]["available"] = (
|
||||||
True
|
self.data["fw-update"]["status"] == "New version is available"
|
||||||
if self.data["fw-update"]["status"] == "New version is available"
|
|
||||||
else False
|
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.data["fw-update"]["available"] = False
|
self.data["fw-update"]["available"] = False
|
||||||
|
|
||||||
|
@ -1594,10 +1595,11 @@ class MikrotikControllerData:
|
||||||
]
|
]
|
||||||
|
|
||||||
if default_gateway:
|
if default_gateway:
|
||||||
to_remove = []
|
to_remove = [
|
||||||
for uid, vals in self.data["arp"].items():
|
uid
|
||||||
if vals["interface"] == default_gateway:
|
for uid, vals in self.data["arp"].items()
|
||||||
to_remove.append(uid)
|
if vals["interface"] == default_gateway
|
||||||
|
]
|
||||||
|
|
||||||
for uid in to_remove:
|
for uid in to_remove:
|
||||||
self.data["arp"].pop(uid)
|
self.data["arp"].pop(uid)
|
||||||
|
@ -1644,11 +1646,10 @@ class MikrotikControllerData:
|
||||||
if not is_valid_ip(self.data["dhcp"][uid]["address"]):
|
if not is_valid_ip(self.data["dhcp"][uid]["address"]):
|
||||||
self.data["dhcp"][uid]["address"] = "unknown"
|
self.data["dhcp"][uid]["address"] = "unknown"
|
||||||
|
|
||||||
if (
|
if self.data["dhcp"][uid]["active-address"] not in [
|
||||||
self.data["dhcp"][uid]["active-address"]
|
self.data["dhcp"][uid]["address"],
|
||||||
!= self.data["dhcp"][uid]["address"]
|
"unknown",
|
||||||
and self.data["dhcp"][uid]["active-address"] != "unknown"
|
]:
|
||||||
):
|
|
||||||
self.data["dhcp"][uid]["address"] = self.data["dhcp"][uid][
|
self.data["dhcp"][uid]["address"] = self.data["dhcp"][uid][
|
||||||
"active-address"
|
"active-address"
|
||||||
]
|
]
|
||||||
|
@ -1656,7 +1657,7 @@ class MikrotikControllerData:
|
||||||
if (
|
if (
|
||||||
self.data["dhcp"][uid]["mac-address"]
|
self.data["dhcp"][uid]["mac-address"]
|
||||||
!= self.data["dhcp"][uid]["active-mac-address"]
|
!= self.data["dhcp"][uid]["active-mac-address"]
|
||||||
and self.data["dhcp"][uid]["active-mac-address"] != "unknown"
|
!= "unknown"
|
||||||
):
|
):
|
||||||
self.data["dhcp"][uid]["mac-address"] = self.data["dhcp"][uid][
|
self.data["dhcp"][uid]["mac-address"] = self.data["dhcp"][uid][
|
||||||
"active-mac-address"
|
"active-mac-address"
|
||||||
|
@ -1741,9 +1742,7 @@ class MikrotikControllerData:
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
def get_wireless_hosts(self):
|
def get_wireless_hosts(self):
|
||||||
"""Get wireless hosts data from Mikrotik"""
|
"""Get wireless hosts data from Mikrotik"""
|
||||||
wifimodule = "wireless"
|
wifimodule = "wifiwave2" if self.support_wifiwave2 else "wireless"
|
||||||
if self.support_wifiwave2:
|
|
||||||
wifimodule = "wifiwave2"
|
|
||||||
self.data["wireless_hosts"] = parse_api(
|
self.data["wireless_hosts"] = parse_api(
|
||||||
data={},
|
data={},
|
||||||
source=self.api.path(f"/interface/{wifimodule}/registration-table"),
|
source=self.api.path(f"/interface/{wifimodule}/registration-table"),
|
||||||
|
@ -1803,8 +1802,7 @@ class MikrotikControllerData:
|
||||||
# Add hosts from DHCP
|
# Add hosts from DHCP
|
||||||
for uid, vals in self.data["dhcp"].items():
|
for uid, vals in self.data["dhcp"].items():
|
||||||
if uid not in self.data["host"]:
|
if uid not in self.data["host"]:
|
||||||
self.data["host"][uid] = {}
|
self.data["host"][uid] = {"source": "dhcp"}
|
||||||
self.data["host"][uid]["source"] = "dhcp"
|
|
||||||
for key in ["address", "mac-address", "interface"]:
|
for key in ["address", "mac-address", "interface"]:
|
||||||
if (
|
if (
|
||||||
key not in self.data["host"][uid]
|
key not in self.data["host"][uid]
|
||||||
|
@ -1815,8 +1813,7 @@ class MikrotikControllerData:
|
||||||
# Add hosts from ARP
|
# Add hosts from ARP
|
||||||
for uid, vals in self.data["arp"].items():
|
for uid, vals in self.data["arp"].items():
|
||||||
if uid not in self.data["host"]:
|
if uid not in self.data["host"]:
|
||||||
self.data["host"][uid] = {}
|
self.data["host"][uid] = {"source": "arp"}
|
||||||
self.data["host"][uid]["source"] = "arp"
|
|
||||||
for key in ["address", "mac-address", "interface"]:
|
for key in ["address", "mac-address", "interface"]:
|
||||||
if (
|
if (
|
||||||
key not in self.data["host"][uid]
|
key not in self.data["host"][uid]
|
||||||
|
@ -1829,8 +1826,7 @@ class MikrotikControllerData:
|
||||||
self.host_hass_recovered = True
|
self.host_hass_recovered = True
|
||||||
for uid in self.data["host_hass"]:
|
for uid in self.data["host_hass"]:
|
||||||
if uid not in self.data["host"]:
|
if uid not in self.data["host"]:
|
||||||
self.data["host"][uid] = {}
|
self.data["host"][uid] = {"source": "restored"}
|
||||||
self.data["host"][uid]["source"] = "restored"
|
|
||||||
self.data["host"][uid]["mac-address"] = uid
|
self.data["host"][uid]["mac-address"] = uid
|
||||||
self.data["host"][uid]["host-name"] = self.data["host_hass"][uid]
|
self.data["host"][uid]["host-name"] = self.data["host_hass"][uid]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue