merged get_sfp into path

This commit is contained in:
Tomaae 2022-06-28 20:13:07 +02:00
parent 8efaa72492
commit 7782503f78
No known key found for this signature in database
GPG key ID: 8360BBD8A381D1C0
2 changed files with 10 additions and 34 deletions

View file

@ -786,7 +786,11 @@ class MikrotikControllerData:
): ):
self.data["interface"] = parse_api( self.data["interface"] = parse_api(
data=self.data["interface"], data=self.data["interface"],
source=self.api.get_sfp(vals[".id"]), source=self.api.path(
"/interface/ethernet",
command="monitor",
args={".id": vals[".id"], "once": True},
),
key_search="name", key_search="name",
vals=[ vals=[
{"name": "status", "default": "unknown"}, {"name": "status", "default": "unknown"},
@ -814,7 +818,11 @@ class MikrotikControllerData:
else: else:
self.data["interface"] = parse_api( self.data["interface"] = parse_api(
data=self.data["interface"], data=self.data["interface"],
source=self.api.get_sfp(vals[".id"]), source=self.api.path(
"/interface/ethernet",
command="monitor",
args={".id": vals[".id"], "once": True},
),
key_search="name", key_search="name",
vals=[ vals=[
{"name": "status", "default": "unknown"}, {"name": "status", "default": "unknown"},

View file

@ -344,38 +344,6 @@ class MikrotikAPI:
self.lock.release() self.lock.release()
return True return True
# ---------------------------
# get_sfp
# ---------------------------
def get_sfp(self, interfaces) -> Optional(list):
"""Get sfp info"""
if not self.connection_check():
return None
response = self.path("/interface/ethernet", return_list=False)
if response is None:
return None
args = {".id": interfaces, "once": True}
self.lock.acquire()
try:
_LOGGER.debug("API query: %s %s", "/interface/ethernet/monitor", interfaces)
sfpinfo = response("monitor", **args)
except Exception as e:
self.disconnect("get_sfp", e)
self.lock.release()
return None
try:
sfpinfo = list(sfpinfo)
except Exception as e:
self.disconnect("get_sfp", e)
self.lock.release()
return None
self.lock.release()
return sfpinfo or None
# --------------------------- # ---------------------------
# arp_ping # arp_ping
# --------------------------- # ---------------------------