added state attributes to interface traffic sensors

This commit is contained in:
Tomaae 2022-02-04 22:55:20 +01:00
parent aa101df363
commit 731cf6cde4
2 changed files with 76 additions and 2 deletions

View file

@ -23,6 +23,8 @@ from .const import (
from .sensor_types import (
MikrotikSensorEntityDescription,
SENSOR_TYPES,
DEVICE_ATTRIBUTES_IFACE_ETHER,
DEVICE_ATTRIBUTES_IFACE_SFP,
)
_LOGGER = logging.getLogger(__name__)
@ -75,8 +77,8 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se
# Entity function
[
MikrotikControllerSensor,
MikrotikControllerSensor,
MikrotikControllerSensor,
MikrotikInterfaceTrafficSensor,
MikrotikInterfaceTrafficSensor,
MikrotikClientTrafficSensor,
MikrotikClientTrafficSensor,
MikrotikClientTrafficSensor,
@ -293,6 +295,30 @@ class MikrotikControllerSensor(SensorEntity):
_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
# ---------------------------