Removed redundant get_dhcp call from update method. Removed unnecessary calls to Mikrotik API for accounting hosts build, reusing new hosts dict. Removed unnecessary variables from mikrotik_controller.py. Reused new dhcp-networks dict. Simplified accounting throughput calculation. Added accounting 'available' and 'local_enabled' parameters for each host. Implemented new parameters on sensor availability.

This commit is contained in:
Ivan Pavlina 2020-04-08 13:41:03 +02:00
parent eee634cfc8
commit 32b93cc8cc
2 changed files with 52 additions and 97 deletions

View file

@ -378,6 +378,16 @@ class MikrotikAccountingSensor(MikrotikControllerSensor):
"""Return a unique_id for this entity."""
return f"{self._inst.lower()}-{self._sensor.lower()}-{self._data['mac-address'].lower()}"
@property
def available(self) -> bool:
"""Return if controller and accounting feature in Mikrotik is available.
Additional check for lan-tx/rx sensors
"""
if self._sensor in ['lan-tx, lan-rx']:
return self._ctrl.connected() and self._data['available'] and self._data['local_accounting']
else:
return self._ctrl.connected() and self._data['available']
@property
def device_info(self):
"""Return a accounting description for device registry."""