Added sensors for total interface tx/rx bytes, fixes #210

This commit is contained in:
Tomaae 2022-06-25 14:34:25 +02:00
parent 574d3137b9
commit 981668032e
No known key found for this signature in database
GPG key ID: 8360BBD8A381D1C0
2 changed files with 44 additions and 0 deletions

View file

@ -700,6 +700,8 @@ class MikrotikControllerData:
{"name": "tx-previous", "default": 0.0}, {"name": "tx-previous", "default": 0.0},
{"name": "rx", "default": 0.0}, {"name": "rx", "default": 0.0},
{"name": "tx", "default": 0.0}, {"name": "tx", "default": 0.0},
{"name": "rx-total", "default": 0.0},
{"name": "tx-total", "default": 0.0},
], ],
skip=[ skip=[
{"name": "type", "value": "bridge"}, {"name": "type", "value": "bridge"},
@ -740,6 +742,9 @@ class MikrotikControllerData:
) )
self.data["interface"][uid]["rx-previous"] = current_rx self.data["interface"][uid]["rx-previous"] = current_rx
self.data["interface"][uid]["tx-total"] = current_tx
self.data["interface"][uid]["rx-total"] = current_rx
self.data["interface"] = parse_api( self.data["interface"] = parse_api(
data=self.data["interface"], data=self.data["interface"],
source=self.api.path("/interface/ethernet"), source=self.api.path("/interface/ethernet"),

View file

@ -13,6 +13,7 @@ from homeassistant.const import (
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
POWER_WATT, POWER_WATT,
PERCENTAGE, PERCENTAGE,
DATA_BYTES,
) )
from .const import DOMAIN from .const import DOMAIN
@ -323,6 +324,44 @@ SENSOR_TYPES = {
data_attributes_list=DEVICE_ATTRIBUTES_IFACE, data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
func="MikrotikInterfaceTrafficSensor", func="MikrotikInterfaceTrafficSensor",
), ),
"total_tx": MikrotikSensorEntityDescription(
key="tx-total",
name="TX total",
icon="mdi:upload-network",
native_unit_of_measurement=DATA_BYTES,
device_class=None,
state_class=SensorStateClass.TOTAL_INCREASING,
entity_category=None,
ha_group="data__default-name",
ha_connection=CONNECTION_NETWORK_MAC,
ha_connection_value="data__port-mac-address",
data_path="interface",
data_attribute="tx-current",
data_name="name",
data_uid="",
data_reference="default-name",
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
func="MikrotikInterfaceTrafficSensor",
),
"total_rx": MikrotikSensorEntityDescription(
key="rx-total",
name="RX total",
icon="mdi:download-network",
native_unit_of_measurement=DATA_BYTES,
device_class=None,
state_class=SensorStateClass.TOTAL_INCREASING,
entity_category=None,
ha_group="data__default-name",
ha_connection=CONNECTION_NETWORK_MAC,
ha_connection_value="data__port-mac-address",
data_path="interface",
data_attribute="rx-current",
data_name="name",
data_uid="",
data_reference="default-name",
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
func="MikrotikInterfaceTrafficSensor",
),
"client_traffic_lan_tx": MikrotikSensorEntityDescription( "client_traffic_lan_tx": MikrotikSensorEntityDescription(
key="client_traffic_lan_tx", key="client_traffic_lan_tx",
name="LAN TX", name="LAN TX",