mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-02 21:44:31 +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,
|
||||
source=None,
|
||||
key=None,
|
||||
key_secondary=None,
|
||||
key_search=None,
|
||||
vals=None,
|
||||
val_proc=None,
|
||||
|
@ -69,7 +70,7 @@ def parse_api(
|
|||
|
||||
uid = None
|
||||
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:
|
||||
continue
|
||||
|
||||
|
@ -92,16 +93,27 @@ def parse_api(
|
|||
# ---------------------------
|
||||
# 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"""
|
||||
uid = None
|
||||
if not key_search:
|
||||
key_primary_found = True
|
||||
if key not in entry:
|
||||
key_primary_found = False
|
||||
|
||||
if key_primary_found and key not in entry and not entry[key]:
|
||||
return None
|
||||
|
||||
if not entry[key]:
|
||||
return None
|
||||
|
||||
if key_primary_found:
|
||||
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:
|
||||
if keymap and key_search in entry and entry[key_search] in keymap:
|
||||
uid = keymap[entry[key_search]]
|
||||
|
|
|
@ -416,6 +416,7 @@ class MikrotikControllerData:
|
|||
data=self.data["interface"],
|
||||
source=self.api.path("/interface"),
|
||||
key="default-name",
|
||||
key_secondary="name",
|
||||
vals=[
|
||||
{"name": "default-name"},
|
||||
{"name": "name", "default_val": "default-name"},
|
||||
|
@ -441,8 +442,17 @@ class MikrotikControllerData:
|
|||
{"name": "rx-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
|
||||
# ---------------------------
|
||||
|
|
|
@ -226,6 +226,8 @@ class MikrotikControllerPortSwitch(MikrotikControllerSwitch):
|
|||
"""Turn on the switch."""
|
||||
path = "/interface"
|
||||
param = "default-name"
|
||||
if "-" in self._data["port-mac-address"]:
|
||||
param = "name"
|
||||
value = self._data[param]
|
||||
mod_param = "disabled"
|
||||
mod_value = False
|
||||
|
@ -236,6 +238,8 @@ class MikrotikControllerPortSwitch(MikrotikControllerSwitch):
|
|||
"""Turn on the switch."""
|
||||
path = "/interface"
|
||||
param = "default-name"
|
||||
if "-" in self._data["port-mac-address"]:
|
||||
param = "name"
|
||||
value = self._data[param]
|
||||
mod_param = "disabled"
|
||||
mod_value = True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue