mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-13 10:54:33 +02:00
Disabled tracking of devices behind default gateway, fixes #139
This commit is contained in:
parent
5d04872032
commit
aee405a9f0
1 changed files with 42 additions and 0 deletions
|
@ -106,6 +106,7 @@ class MikrotikControllerData:
|
|||
self.data = {
|
||||
"routerboard": {},
|
||||
"resource": {},
|
||||
"route": {},
|
||||
"health": {},
|
||||
"health7": {},
|
||||
"interface": {},
|
||||
|
@ -585,6 +586,9 @@ class MikrotikControllerData:
|
|||
if self.api.connected():
|
||||
await self.hass.async_add_executor_job(self.get_system_health)
|
||||
|
||||
if self.api.connected():
|
||||
await self.hass.async_add_executor_job(self.get_route)
|
||||
|
||||
if self.api.connected():
|
||||
await self.hass.async_add_executor_job(self.get_interface)
|
||||
|
||||
|
@ -814,6 +818,28 @@ class MikrotikControllerData:
|
|||
)
|
||||
self.data["interface"][uid]["rx-previous"] = current_rx
|
||||
|
||||
# ---------------------------
|
||||
# get_route
|
||||
# ---------------------------
|
||||
def get_route(self):
|
||||
"""Get system resources data from Mikrotik"""
|
||||
self.data["route"] = parse_api(
|
||||
data={},
|
||||
source=self.api.path("/ip/route"),
|
||||
key="dst-address",
|
||||
vals=[
|
||||
{"name": "dst-address"},
|
||||
{"name": "gateway", "default": "unknown"},
|
||||
{"name": "vrf-interface", "default": "unknown"},
|
||||
{
|
||||
"name": "enabled",
|
||||
"source": "disabled",
|
||||
"type": "bool",
|
||||
"reverse": True,
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
# ---------------------------
|
||||
# get_bridge
|
||||
# ---------------------------
|
||||
|
@ -1561,6 +1587,13 @@ class MikrotikControllerData:
|
|||
ensure_vals=[{"name": "bridge", "default": ""}],
|
||||
)
|
||||
|
||||
default_gateway = ""
|
||||
if (
|
||||
"0.0.0.0/0" in self.data["route"]
|
||||
and self.data["route"]["0.0.0.0/0"]["vrf-interface"]
|
||||
):
|
||||
default_gateway = self.data["route"]["0.0.0.0/0"]["vrf-interface"]
|
||||
|
||||
for uid, vals in self.data["arp"].items():
|
||||
if (
|
||||
vals["interface"] in self.data["bridge"]
|
||||
|
@ -1571,6 +1604,15 @@ class MikrotikControllerData:
|
|||
"interface"
|
||||
]
|
||||
|
||||
if default_gateway:
|
||||
to_remove = []
|
||||
for uid, vals in self.data["arp"].items():
|
||||
if vals["interface"] == default_gateway:
|
||||
to_remove.append(uid)
|
||||
|
||||
for uid in to_remove:
|
||||
self.data["arp"].pop(uid)
|
||||
|
||||
# ---------------------------
|
||||
# get_dns
|
||||
# ---------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue