mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-05 15:04:30 +02:00
removed extra cycle in sensor update_items
This commit is contained in:
parent
8b410eab19
commit
f1a239f118
1 changed files with 18 additions and 23 deletions
|
@ -103,33 +103,28 @@ def update_items(inst, mikrotik_controller, async_add_entities, sensors):
|
||||||
"""Update sensor state from the controller."""
|
"""Update sensor state from the controller."""
|
||||||
new_sensors = []
|
new_sensors = []
|
||||||
|
|
||||||
for sensor in SENSOR_TYPES:
|
|
||||||
if "traffic_" in sensor:
|
|
||||||
continue
|
|
||||||
|
|
||||||
item_id = "{}-{}".format(inst, sensor)
|
|
||||||
if item_id in sensors:
|
|
||||||
if sensors[item_id].enabled:
|
|
||||||
sensors[item_id].async_schedule_update_ha_state()
|
|
||||||
continue
|
|
||||||
|
|
||||||
sensors[item_id] = MikrotikControllerSensor(mikrotik_controller=mikrotik_controller, inst=inst, sensor=sensor)
|
|
||||||
new_sensors.append(sensors[item_id])
|
|
||||||
|
|
||||||
for sensor in SENSOR_TYPES:
|
for sensor in SENSOR_TYPES:
|
||||||
if "traffic_" not in sensor:
|
if "traffic_" not in sensor:
|
||||||
continue
|
item_id = "{}-{}".format(inst, sensor)
|
||||||
|
if item_id in sensors:
|
||||||
|
if sensors[item_id].enabled:
|
||||||
|
sensors[item_id].async_schedule_update_ha_state()
|
||||||
|
continue
|
||||||
|
|
||||||
for uid in mikrotik_controller.data['interface']:
|
sensors[item_id] = MikrotikControllerSensor(mikrotik_controller=mikrotik_controller, inst=inst, sensor=sensor)
|
||||||
if mikrotik_controller.data['interface'][uid]['type'] == "ether":
|
new_sensors.append(sensors[item_id])
|
||||||
item_id = "{}-{}-{}".format(inst, sensor, mikrotik_controller.data['interface'][uid]['default-name'])
|
|
||||||
if item_id in sensors:
|
|
||||||
if sensors[item_id].enabled:
|
|
||||||
sensors[item_id].async_schedule_update_ha_state()
|
|
||||||
continue
|
|
||||||
|
|
||||||
sensors[item_id] = MikrotikControllerTrafficSensor(mikrotik_controller=mikrotik_controller, inst=inst, sensor=sensor, uid=uid)
|
if "traffic_" in sensor:
|
||||||
new_sensors.append(sensors[item_id])
|
for uid in mikrotik_controller.data['interface']:
|
||||||
|
if mikrotik_controller.data['interface'][uid]['type'] == "ether":
|
||||||
|
item_id = "{}-{}-{}".format(inst, sensor, mikrotik_controller.data['interface'][uid]['default-name'])
|
||||||
|
if item_id in sensors:
|
||||||
|
if sensors[item_id].enabled:
|
||||||
|
sensors[item_id].async_schedule_update_ha_state()
|
||||||
|
continue
|
||||||
|
|
||||||
|
sensors[item_id] = MikrotikControllerTrafficSensor(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