diff --git a/custom_components/mikrotik_router/helper.py b/custom_components/mikrotik_router/helper.py index f1730fc..8be4a86 100644 --- a/custom_components/mikrotik_router/helper.py +++ b/custom_components/mikrotik_router/helper.py @@ -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: - return None + key_primary_found = False - if not entry[key]: + if key_primary_found and key not in entry and not entry[key]: return None - uid = entry[key] + 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]] diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 8364da3..3534d69 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -416,6 +416,7 @@ def get_interface(self): 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 @@ def get_interface(self): {"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 # --------------------------- diff --git a/custom_components/mikrotik_router/switch.py b/custom_components/mikrotik_router/switch.py index 23dc514..53bc544 100644 --- a/custom_components/mikrotik_router/switch.py +++ b/custom_components/mikrotik_router/switch.py @@ -226,6 +226,8 @@ async def async_turn_on(self): """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 @@ async def async_turn_off(self): """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