diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 1935539..a48cdee 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -33,6 +33,12 @@ from .const import ( DEFAULT_SCAN_INTERVAL, DEFAULT_UNIT_OF_MEASUREMENT, CONF_TRACK_HOSTS_TIMEOUT, + CONF_SENSOR_PORT_TRAFFIC, + DEFAULT_SENSOR_PORT_TRAFFIC, + CONF_SENSOR_CLIENT_TRAFFIC, + DEFAULT_SENSOR_CLIENT_TRAFFIC, + CONF_SENSOR_SIMPLE_QUEUES, + DEFAULT_SENSOR_SIMPLE_QUEUES, ) from .exceptions import ApiEntryNotFound from .helper import parse_api @@ -143,6 +149,36 @@ class MikrotikControllerData: """Config entry option to not track ARP.""" return self.config_entry.options.get(CONF_TRACK_HOSTS, DEFAULT_TRACK_HOSTS) + # --------------------------- + # option_sensor_port_traffic + # --------------------------- + @property + def option_sensor_port_traffic(self): + """Config entry option to not track ARP.""" + return self.config_entry.options.get( + CONF_SENSOR_PORT_TRAFFIC, DEFAULT_SENSOR_PORT_TRAFFIC + ) + + # --------------------------- + # option_sensor_client_traffic + # --------------------------- + @property + def option_sensor_client_traffic(self): + """Config entry option to not track ARP.""" + return self.config_entry.options.get( + CONF_SENSOR_CLIENT_TRAFFIC, DEFAULT_SENSOR_CLIENT_TRAFFIC + ) + + # --------------------------- + # option_sensor_simple_queues + # --------------------------- + @property + def option_sensor_simple_queues(self): + """Config entry option to not track ARP.""" + return self.config_entry.options.get( + CONF_SENSOR_SIMPLE_QUEUES, DEFAULT_SENSOR_SIMPLE_QUEUES + ) + # --------------------------- # option_scan_interval # --------------------------- @@ -411,7 +447,7 @@ class MikrotikControllerData: if self.api.connected(): await self.async_process_host() - if self.api.connected(): + if self.api.connected() and self.option_sensor_port_traffic: await self.hass.async_add_executor_job(self.get_interface_traffic) if self.api.connected(): diff --git a/custom_components/mikrotik_router/sensor.py b/custom_components/mikrotik_router/sensor.py index 78d34cc..8aa76d4 100644 --- a/custom_components/mikrotik_router/sensor.py +++ b/custom_components/mikrotik_router/sensor.py @@ -8,6 +8,12 @@ from homeassistant.const import ( ATTR_DEVICE_CLASS, TEMP_CELSIUS, ) + +from .const import ( + CONF_SENSOR_PORT_TRAFFIC, + DEFAULT_SENSOR_PORT_TRAFFIC, +) + from homeassistant.core import callback from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -155,7 +161,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): @callback def update_controller(): """Update the values of the controller.""" - update_items(inst, mikrotik_controller, async_add_entities, sensors) + update_items( + inst, config_entry, mikrotik_controller, async_add_entities, sensors + ) mikrotik_controller.listeners.append( async_dispatcher_connect( @@ -170,7 +178,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # update_items # --------------------------- @callback -def update_items(inst, mikrotik_controller, async_add_entities, sensors): +def update_items(inst, config_entry, mikrotik_controller, async_add_entities, sensors): """Update sensor state from the controller.""" new_sensors = [] @@ -189,6 +197,11 @@ def update_items(inst, mikrotik_controller, async_add_entities, sensors): new_sensors.append(sensors[item_id]) if "traffic_" in sensor: + if not config_entry.options.get( + CONF_SENSOR_PORT_TRAFFIC, DEFAULT_SENSOR_PORT_TRAFFIC + ): + continue + for uid in mikrotik_controller.data["interface"]: if mikrotik_controller.data["interface"][uid]["type"] != "bridge": item_id = f"{inst}-{sensor}-{mikrotik_controller.data['interface'][uid]['default-name']}"