mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-03 22:14:32 +02:00
added support for virtual interfaces #12
This commit is contained in:
parent
99d6d7c43b
commit
cd4d0a09ee
3 changed files with 31 additions and 5 deletions
|
@ -44,6 +44,7 @@ def parse_api(
|
||||||
data=None,
|
data=None,
|
||||||
source=None,
|
source=None,
|
||||||
key=None,
|
key=None,
|
||||||
|
key_secondary=None,
|
||||||
key_search=None,
|
key_search=None,
|
||||||
vals=None,
|
vals=None,
|
||||||
val_proc=None,
|
val_proc=None,
|
||||||
|
@ -69,7 +70,7 @@ def parse_api(
|
||||||
|
|
||||||
uid = None
|
uid = None
|
||||||
if key or key_search:
|
if key or key_search:
|
||||||
uid = get_uid(entry, key, key_search, keymap)
|
uid = get_uid(entry, key, key_secondary, key_search, keymap)
|
||||||
if not uid:
|
if not uid:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -92,16 +93,27 @@ def parse_api(
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# get_uid
|
# get_uid
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
def get_uid(entry, key, key_search, keymap) -> Optional(str):
|
def get_uid(entry, key, key_secondary, key_search, keymap) -> Optional(str):
|
||||||
"""Get UID for data list"""
|
"""Get UID for data list"""
|
||||||
|
uid = None
|
||||||
if not key_search:
|
if not key_search:
|
||||||
|
key_primary_found = True
|
||||||
if key not in entry:
|
if key not in entry:
|
||||||
|
key_primary_found = False
|
||||||
|
|
||||||
|
if key_primary_found and key not in entry and not entry[key]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not entry[key]:
|
if key_primary_found:
|
||||||
return None
|
|
||||||
|
|
||||||
uid = entry[key]
|
uid = entry[key]
|
||||||
|
elif key_secondary:
|
||||||
|
if key_secondary not in entry:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if not entry[key_secondary]:
|
||||||
|
return None
|
||||||
|
|
||||||
|
uid = entry[key_secondary]
|
||||||
else:
|
else:
|
||||||
if keymap and key_search in entry and entry[key_search] in keymap:
|
if keymap and key_search in entry and entry[key_search] in keymap:
|
||||||
uid = keymap[entry[key_search]]
|
uid = keymap[entry[key_search]]
|
||||||
|
|
|
@ -416,6 +416,7 @@ class MikrotikControllerData:
|
||||||
data=self.data["interface"],
|
data=self.data["interface"],
|
||||||
source=self.api.path("/interface"),
|
source=self.api.path("/interface"),
|
||||||
key="default-name",
|
key="default-name",
|
||||||
|
key_secondary="name",
|
||||||
vals=[
|
vals=[
|
||||||
{"name": "default-name"},
|
{"name": "default-name"},
|
||||||
{"name": "name", "default_val": "default-name"},
|
{"name": "name", "default_val": "default-name"},
|
||||||
|
@ -441,8 +442,17 @@ class MikrotikControllerData:
|
||||||
{"name": "rx-bits-per-second", "default": 0},
|
{"name": "rx-bits-per-second", "default": 0},
|
||||||
{"name": "tx-bits-per-second", "default": 0},
|
{"name": "tx-bits-per-second", "default": 0},
|
||||||
],
|
],
|
||||||
|
skip=[{"name": "type", "value": "bridge"}],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Udpate virtual interfaces
|
||||||
|
for uid, vals in self.data["interface"].items():
|
||||||
|
if vals["default-name"] == "":
|
||||||
|
self.data["interface"][uid]["default-name"] = vals["name"]
|
||||||
|
self.data["interface"][uid][
|
||||||
|
"port-mac-address"
|
||||||
|
] = f"{vals['port-mac-address']}-{vals['name']}"
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# get_interface_traffic
|
# get_interface_traffic
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
|
@ -226,6 +226,8 @@ class MikrotikControllerPortSwitch(MikrotikControllerSwitch):
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
path = "/interface"
|
path = "/interface"
|
||||||
param = "default-name"
|
param = "default-name"
|
||||||
|
if "-" in self._data["port-mac-address"]:
|
||||||
|
param = "name"
|
||||||
value = self._data[param]
|
value = self._data[param]
|
||||||
mod_param = "disabled"
|
mod_param = "disabled"
|
||||||
mod_value = False
|
mod_value = False
|
||||||
|
@ -236,6 +238,8 @@ class MikrotikControllerPortSwitch(MikrotikControllerSwitch):
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
path = "/interface"
|
path = "/interface"
|
||||||
param = "default-name"
|
param = "default-name"
|
||||||
|
if "-" in self._data["port-mac-address"]:
|
||||||
|
param = "name"
|
||||||
value = self._data[param]
|
value = self._data[param]
|
||||||
mod_param = "disabled"
|
mod_param = "disabled"
|
||||||
mod_value = True
|
mod_value = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue