mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-30 15:34:31 +02:00
Modified checking of sensor type name logic to prevent false positives. Removed excessive logging.
This commit is contained in:
parent
e93b02e71d
commit
7ffb5202ec
2 changed files with 22 additions and 25 deletions
|
@ -614,10 +614,8 @@ class MikrotikControllerData:
|
||||||
|
|
||||||
if self.api.connected() and self.option_sensor_client_traffic:
|
if self.api.connected() and self.option_sensor_client_traffic:
|
||||||
if 0 < self.major_fw_version < 7:
|
if 0 < self.major_fw_version < 7:
|
||||||
_LOGGER.info("Using accounting feature for client traffic processing")
|
|
||||||
await self.hass.async_add_executor_job(self.process_accounting)
|
await self.hass.async_add_executor_job(self.process_accounting)
|
||||||
elif 0 < self.major_fw_version >= 7:
|
elif 0 < self.major_fw_version >= 7:
|
||||||
_LOGGER.info("Using accounting kid control devices for client traffic processing")
|
|
||||||
await self.hass.async_add_executor_job(self.process_kid_control_devices)
|
await self.hass.async_add_executor_job(self.process_kid_control_devices)
|
||||||
|
|
||||||
if self.api.connected() and self.option_sensor_simple_queues:
|
if self.api.connected() and self.option_sensor_simple_queues:
|
||||||
|
@ -2172,4 +2170,3 @@ class MikrotikControllerData:
|
||||||
break
|
break
|
||||||
|
|
||||||
return uid
|
return uid
|
||||||
|
|
||||||
|
|
|
@ -305,7 +305,7 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se
|
||||||
new_sensors.append(sensors[item_id])
|
new_sensors.append(sensors[item_id])
|
||||||
|
|
||||||
for sensor in SENSOR_TYPES:
|
for sensor in SENSOR_TYPES:
|
||||||
if "system_" in sensor:
|
if sensor.startswith("system_"):
|
||||||
if (
|
if (
|
||||||
SENSOR_TYPES[sensor][ATTR_ATTR]
|
SENSOR_TYPES[sensor][ATTR_ATTR]
|
||||||
not in mikrotik_controller.data[SENSOR_TYPES[sensor][ATTR_PATH]]
|
not in mikrotik_controller.data[SENSOR_TYPES[sensor][ATTR_PATH]]
|
||||||
|
@ -327,27 +327,7 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se
|
||||||
)
|
)
|
||||||
new_sensors.append(sensors[item_id])
|
new_sensors.append(sensors[item_id])
|
||||||
|
|
||||||
if "client_traffic_" in sensor:
|
if sensor.startswith("traffic_"):
|
||||||
for uid in mikrotik_controller.data["client_traffic"]:
|
|
||||||
item_id = f"{inst}-{sensor}-{mikrotik_controller.data['client_traffic'][uid]['mac-address']}"
|
|
||||||
if item_id in sensors:
|
|
||||||
if sensors[item_id].enabled:
|
|
||||||
sensors[item_id].async_schedule_update_ha_state()
|
|
||||||
continue
|
|
||||||
|
|
||||||
if (
|
|
||||||
SENSOR_TYPES[sensor][ATTR_ATTR]
|
|
||||||
in mikrotik_controller.data["client_traffic"][uid].keys()
|
|
||||||
):
|
|
||||||
sensors[item_id] = MikrotikClientTrafficSensor(
|
|
||||||
mikrotik_controller=mikrotik_controller,
|
|
||||||
inst=inst,
|
|
||||||
sensor=sensor,
|
|
||||||
uid=uid,
|
|
||||||
)
|
|
||||||
new_sensors.append(sensors[item_id])
|
|
||||||
|
|
||||||
if "traffic_" in sensor:
|
|
||||||
if not config_entry.options.get(
|
if not config_entry.options.get(
|
||||||
CONF_SENSOR_PORT_TRAFFIC, DEFAULT_SENSOR_PORT_TRAFFIC
|
CONF_SENSOR_PORT_TRAFFIC, DEFAULT_SENSOR_PORT_TRAFFIC
|
||||||
):
|
):
|
||||||
|
@ -370,6 +350,26 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se
|
||||||
)
|
)
|
||||||
new_sensors.append(sensors[item_id])
|
new_sensors.append(sensors[item_id])
|
||||||
|
|
||||||
|
if sensor.startswith("client_traffic_"):
|
||||||
|
for uid in mikrotik_controller.data["client_traffic"]:
|
||||||
|
item_id = f"{inst}-{sensor}-{mikrotik_controller.data['client_traffic'][uid]['mac-address']}"
|
||||||
|
if item_id in sensors:
|
||||||
|
if sensors[item_id].enabled:
|
||||||
|
sensors[item_id].async_schedule_update_ha_state()
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (
|
||||||
|
SENSOR_TYPES[sensor][ATTR_ATTR]
|
||||||
|
in mikrotik_controller.data["client_traffic"][uid].keys()
|
||||||
|
):
|
||||||
|
sensors[item_id] = MikrotikClientTrafficSensor(
|
||||||
|
mikrotik_controller=mikrotik_controller,
|
||||||
|
inst=inst,
|
||||||
|
sensor=sensor,
|
||||||
|
uid=uid,
|
||||||
|
)
|
||||||
|
new_sensors.append(sensors[item_id])
|
||||||
|
|
||||||
|
|
||||||
if new_sensors:
|
if new_sensors:
|
||||||
async_add_entities(new_sensors, True)
|
async_add_entities(new_sensors, True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue