mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-22 11:44:23 +02:00
Added status, rate, duplex and negotiation status to ethernet ports #146
This commit is contained in:
parent
052c1f1e7d
commit
b04a0a5b26
3 changed files with 105 additions and 41 deletions
|
@ -60,6 +60,25 @@ DEVICE_ATTRIBUTES_IFACE = [
|
|||
"actual-mtu",
|
||||
"type",
|
||||
"name",
|
||||
]
|
||||
|
||||
DEVICE_ATTRIBUTES_IFACE_ETHER = [
|
||||
"running",
|
||||
"enabled",
|
||||
"comment",
|
||||
"client-ip-address",
|
||||
"client-mac-address",
|
||||
"port-mac-address",
|
||||
"last-link-down-time",
|
||||
"last-link-up-time",
|
||||
"link-downs",
|
||||
"actual-mtu",
|
||||
"type",
|
||||
"name",
|
||||
"status",
|
||||
"auto-negotiation",
|
||||
"rate",
|
||||
"full-duplex",
|
||||
"default-name",
|
||||
"poe-out",
|
||||
]
|
||||
|
@ -476,7 +495,9 @@ class MikrotikControllerPortBinarySensor(MikrotikControllerBinarySensor):
|
|||
def extra_state_attributes(self) -> Dict[str, Any]:
|
||||
"""Return the state attributes."""
|
||||
attributes = self._attrs
|
||||
for variable in DEVICE_ATTRIBUTES_IFACE:
|
||||
|
||||
if self._data["type"] == "ether":
|
||||
for variable in DEVICE_ATTRIBUTES_IFACE_ETHER:
|
||||
if variable in self._data:
|
||||
attributes[format_attribute(variable)] = self._data[variable]
|
||||
|
||||
|
@ -485,6 +506,11 @@ class MikrotikControllerPortBinarySensor(MikrotikControllerBinarySensor):
|
|||
if variable in self._data:
|
||||
attributes[format_attribute(variable)] = self._data[variable]
|
||||
|
||||
else:
|
||||
for variable in self._sid_data["sid_attr"]:
|
||||
if variable in self._data:
|
||||
attributes[format_attribute(variable)] = self._data[variable]
|
||||
|
||||
return attributes
|
||||
|
||||
@property
|
||||
|
|
|
@ -698,6 +698,7 @@ class MikrotikControllerData:
|
|||
"port-mac-address"
|
||||
] = f"{vals['port-mac-address']}-{vals['name']}"
|
||||
|
||||
if self.data["interface"][uid]["type"] == "ether":
|
||||
if (
|
||||
"sfp-shutdown-temperature" in vals
|
||||
and vals["sfp-shutdown-temperature"] != ""
|
||||
|
@ -729,6 +730,18 @@ class MikrotikControllerData:
|
|||
{"name": "eeprom-checksum", "default": "unknown"},
|
||||
],
|
||||
)
|
||||
else:
|
||||
self.data["interface"] = parse_api(
|
||||
data=self.data["interface"],
|
||||
source=self.api.get_sfp(vals[".id"]),
|
||||
key_search="name",
|
||||
vals=[
|
||||
{"name": "status", "default": "unknown"},
|
||||
{"name": "rate", "default": "unknown"},
|
||||
{"name": "full-duplex", "default": "unknown"},
|
||||
{"name": "auto-negotiation", "default": "unknown"},
|
||||
],
|
||||
)
|
||||
|
||||
# ---------------------------
|
||||
# get_interface_traffic
|
||||
|
|
|
@ -27,6 +27,25 @@ DEVICE_ATTRIBUTES_IFACE = [
|
|||
"actual-mtu",
|
||||
"type",
|
||||
"name",
|
||||
]
|
||||
|
||||
DEVICE_ATTRIBUTES_IFACE_ETHER = [
|
||||
"running",
|
||||
"enabled",
|
||||
"comment",
|
||||
"client-ip-address",
|
||||
"client-mac-address",
|
||||
"port-mac-address",
|
||||
"last-link-down-time",
|
||||
"last-link-up-time",
|
||||
"link-downs",
|
||||
"actual-mtu",
|
||||
"type",
|
||||
"name",
|
||||
"status",
|
||||
"auto-negotiation",
|
||||
"rate",
|
||||
"full-duplex",
|
||||
"default-name",
|
||||
"poe-out",
|
||||
]
|
||||
|
@ -379,7 +398,8 @@ class MikrotikControllerPortSwitch(MikrotikControllerSwitch):
|
|||
"""Return the state attributes."""
|
||||
attributes = self._attrs
|
||||
|
||||
for variable in self._sid_data["sid_attr"]:
|
||||
if self._data["type"] == "ether":
|
||||
for variable in DEVICE_ATTRIBUTES_IFACE_ETHER:
|
||||
if variable in self._data:
|
||||
attributes[format_attribute(variable)] = self._data[variable]
|
||||
|
||||
|
@ -388,6 +408,11 @@ class MikrotikControllerPortSwitch(MikrotikControllerSwitch):
|
|||
if variable in self._data:
|
||||
attributes[format_attribute(variable)] = self._data[variable]
|
||||
|
||||
else:
|
||||
for variable in self._sid_data["sid_attr"]:
|
||||
if variable in self._data:
|
||||
attributes[format_attribute(variable)] = self._data[variable]
|
||||
|
||||
return attributes
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue