From 3c44445cd14d2a4581a203684b606a0c7d3f5b8a Mon Sep 17 00:00:00 2001 From: Ivan Pavlina Date: Tue, 7 Apr 2020 14:57:29 +0200 Subject: [PATCH] Fix for naming of static DNS entries without host-name and static DNS entry. Fallback value is not mac-address --- README.md | 5 ++--- custom_components/mikrotik_router/mikrotik_controller.py | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e0da443..08f44c5 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ You can add this integration several times for different devices. * "Port" - Leave at 0 for defaults * "Name of the integration" - Friendy name for this router * "Unit of measurement" - Traffic sensor measurement (bps, Kbps, Mbps, B/s, KB/s, MB/s) -* "Track accounting" - Determines if integration will track per-host throughput. Accounting must be enabled in Mikrotik first # Configuration ![Integration options](https://raw.githubusercontent.com/tomaae/homeassistant-mikrotik_router/master/docs/assets/images/ui/integration_options.png) @@ -67,7 +66,7 @@ For per-IP throughput tracking Mikrotik's accounting feature is used. [Mikrotik support page](https://wiki.mikrotik.com/wiki/Manual:IP/Accounting) -Before setting up integration in HA, go in Winbox IP-Accounting and setup the feature. Make sure that threshold is set to resonable value to store all connections between user defined scan interval. Max value is 8192 so for piece of mind i recommend setting that value. Web Access is not needed, integration is using API access. +Feature will be automaticaly used if accounting is enabled in Mikrotik. Feature is present in Winbox IP-Accounting. Make sure that threshold is set to resonable value to store all connections between user defined scan interval. Max value is 8192 so for piece of mind i recommend setting that value. Web Access is not needed, integration is using API access. Integration will scan DHCP Lease table and ARP table to generate all known hosts and create two sensors for WAN traffic (mikrotik-XXX-wan-rx and mikrotik-XXX-wan-tx). If the parameter *account-local-traffic* is set in Mikrotik's accounting configuration it will also create two sensors for LAN traffic (mikrotik-XXX-lan-rx and mikrotik-XXX-lan-tx). @@ -75,4 +74,4 @@ Device's name will be determined by first available string this order: 1. DHCP lease comment 2. DNS static entry 3. DHCP hostname -4. Device's IP address +4. Device's MAC address diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 9776030..a65cfc7 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -788,9 +788,12 @@ class MikrotikControllerData: # Then static DNS entry elif vals['address'] in dns_data and str(dns_data[vals['address']].get('name', '').strip()): self.data["accounting"][mac]['name'] = dns_data[vals['address']]['name'] - # If everything fails use hosts DHCP lease host-name - else: + # Then DHCP lease host-name + elif str(vals.get('host-name', '').strip()): self.data["accounting"][mac]['name'] = vals['host-name'] + # If everything fails fallback to device's MAC address + else: + self.data["accounting"][mac]['name'] = vals['mac-address'] _LOGGER.debug(f"Generated {len(self.data['accounting'])} accounting devices")