mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-16 12:24:30 +02:00
added state attributes to interface traffic sensors
This commit is contained in:
parent
aa101df363
commit
731cf6cde4
2 changed files with 76 additions and 2 deletions
|
@ -23,6 +23,8 @@ from .const import (
|
||||||
from .sensor_types import (
|
from .sensor_types import (
|
||||||
MikrotikSensorEntityDescription,
|
MikrotikSensorEntityDescription,
|
||||||
SENSOR_TYPES,
|
SENSOR_TYPES,
|
||||||
|
DEVICE_ATTRIBUTES_IFACE_ETHER,
|
||||||
|
DEVICE_ATTRIBUTES_IFACE_SFP,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -75,8 +77,8 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se
|
||||||
# Entity function
|
# Entity function
|
||||||
[
|
[
|
||||||
MikrotikControllerSensor,
|
MikrotikControllerSensor,
|
||||||
MikrotikControllerSensor,
|
MikrotikInterfaceTrafficSensor,
|
||||||
MikrotikControllerSensor,
|
MikrotikInterfaceTrafficSensor,
|
||||||
MikrotikClientTrafficSensor,
|
MikrotikClientTrafficSensor,
|
||||||
MikrotikClientTrafficSensor,
|
MikrotikClientTrafficSensor,
|
||||||
MikrotikClientTrafficSensor,
|
MikrotikClientTrafficSensor,
|
||||||
|
@ -293,6 +295,30 @@ class MikrotikControllerSensor(SensorEntity):
|
||||||
_LOGGER.debug("New sensor %s (%s)", self._inst, self.unique_id)
|
_LOGGER.debug("New sensor %s (%s)", self._inst, self.unique_id)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# MikrotikInterfaceTrafficSensor
|
||||||
|
# ---------------------------
|
||||||
|
class MikrotikInterfaceTrafficSensor(MikrotikControllerSensor):
|
||||||
|
"""Define an Mikrotik MikrotikInterfaceTrafficSensor sensor."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def extra_state_attributes(self) -> Mapping[str, Any]:
|
||||||
|
"""Return the state attributes."""
|
||||||
|
attributes = super().extra_state_attributes
|
||||||
|
|
||||||
|
if self._data["type"] == "ether":
|
||||||
|
for variable in DEVICE_ATTRIBUTES_IFACE_ETHER:
|
||||||
|
if variable in self._data:
|
||||||
|
attributes[format_attribute(variable)] = self._data[variable]
|
||||||
|
|
||||||
|
if "sfp-shutdown-temperature" in self._data:
|
||||||
|
for variable in DEVICE_ATTRIBUTES_IFACE_SFP:
|
||||||
|
if variable in self._data:
|
||||||
|
attributes[format_attribute(variable)] = self._data[variable]
|
||||||
|
|
||||||
|
return attributes
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# MikrotikClientTrafficSensor
|
# MikrotikClientTrafficSensor
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
|
@ -16,6 +16,52 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
DEVICE_ATTRIBUTES_IFACE = [
|
||||||
|
"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",
|
||||||
|
]
|
||||||
|
|
||||||
|
DEVICE_ATTRIBUTES_IFACE_ETHER = [
|
||||||
|
"status",
|
||||||
|
"auto-negotiation",
|
||||||
|
"rate",
|
||||||
|
"full-duplex",
|
||||||
|
"default-name",
|
||||||
|
"poe-out",
|
||||||
|
]
|
||||||
|
|
||||||
|
DEVICE_ATTRIBUTES_IFACE_SFP = [
|
||||||
|
"status",
|
||||||
|
"auto-negotiation",
|
||||||
|
"advertising",
|
||||||
|
"link-partner-advertising",
|
||||||
|
"sfp-temperature",
|
||||||
|
"sfp-supply-voltage",
|
||||||
|
"sfp-module-present",
|
||||||
|
"sfp-tx-bias-current",
|
||||||
|
"sfp-tx-power",
|
||||||
|
"sfp-rx-power",
|
||||||
|
"sfp-rx-loss",
|
||||||
|
"sfp-tx-fault",
|
||||||
|
"sfp-type",
|
||||||
|
"sfp-connector-type",
|
||||||
|
"sfp-vendor-name",
|
||||||
|
"sfp-vendor-part-number",
|
||||||
|
"sfp-vendor-revision",
|
||||||
|
"sfp-vendor-serial",
|
||||||
|
"sfp-manufacturing-date",
|
||||||
|
"eeprom-checksum",
|
||||||
|
]
|
||||||
|
|
||||||
DEVICE_ATTRIBUTES_CLIENT_TRAFFIC = ["address", "mac-address", "host-name"]
|
DEVICE_ATTRIBUTES_CLIENT_TRAFFIC = ["address", "mac-address", "host-name"]
|
||||||
|
|
||||||
|
@ -217,6 +263,7 @@ SENSOR_TYPES = {
|
||||||
data_name="name",
|
data_name="name",
|
||||||
data_uid="",
|
data_uid="",
|
||||||
data_reference="default-name",
|
data_reference="default-name",
|
||||||
|
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
||||||
),
|
),
|
||||||
"traffic_rx": MikrotikSensorEntityDescription(
|
"traffic_rx": MikrotikSensorEntityDescription(
|
||||||
key="traffic_rx",
|
key="traffic_rx",
|
||||||
|
@ -234,6 +281,7 @@ SENSOR_TYPES = {
|
||||||
data_name="name",
|
data_name="name",
|
||||||
data_uid="",
|
data_uid="",
|
||||||
data_reference="default-name",
|
data_reference="default-name",
|
||||||
|
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
||||||
),
|
),
|
||||||
"client_traffic_lan_tx": MikrotikSensorEntityDescription(
|
"client_traffic_lan_tx": MikrotikSensorEntityDescription(
|
||||||
key="client_traffic_lan_tx",
|
key="client_traffic_lan_tx",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue