mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-02 21:44:31 +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 (
|
||||
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
|
||||
# ---------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue