flake8 compliance

This commit is contained in:
tomaae 2019-12-02 17:59:49 +01:00
parent d8b9294483
commit 0a6c8d369d
5 changed files with 81 additions and 82 deletions

View file

@ -4,7 +4,7 @@ from datetime import timedelta
import logging
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_track_time_interval
#from homeassistant.util import Throttle
# from homeassistant.util import Throttle
from .const import (
DOMAIN,
@ -14,15 +14,15 @@ from .const import (
DEFAULT_SCAN_INTERVAL,
)
_LOGGER = logging.getLogger(__name__)
from .mikrotikapi import MikrotikAPI
#DEFAULT_SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL)
_LOGGER = logging.getLogger(__name__)
# DEFAULT_SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL)
#---------------------------
# ---------------------------
# MikrotikControllerData
#---------------------------
# ---------------------------
class MikrotikControllerData():
def __init__(self, hass, config_entry, name, host, port, username, password, use_ssl):
"""Initialize."""
@ -51,51 +51,51 @@ class MikrotikControllerData():
await self.async_update()
return
#---------------------------
# ---------------------------
# option_track_arp
#---------------------------
# ---------------------------
@property
def option_track_arp(self):
"""Config entry option to not track ARP."""
return self.config_entry.options.get(CONF_TRACK_ARP, DEFAULT_TRACK_ARP)
#---------------------------
# ---------------------------
# option_scan_interval
#---------------------------
# ---------------------------
@property
def option_scan_interval(self):
"""Config entry option scan interval."""
scan_interval = self.config_entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
return timedelta(seconds=scan_interval)
#---------------------------
# ---------------------------
# signal_update
#---------------------------
# ---------------------------
@property
def signal_update(self):
"""Event specific per UniFi entry to signal new data."""
return f"{DOMAIN}-update-{self.name}"
#---------------------------
# ---------------------------
# connected
#---------------------------
# ---------------------------
def connected(self):
"""Return connected boolean."""
return self.api.connected()
#---------------------------
# ---------------------------
# hwinfo_update
#---------------------------
# ---------------------------
async def hwinfo_update(self):
"""Update Mikrotik hardware info."""
self.get_system_routerboard()
self.get_system_resource()
return
#---------------------------
# ---------------------------
# async_update
#---------------------------
#@Throttle(DEFAULT_SCAN_INTERVAL)
# ---------------------------
# @Throttle(DEFAULT_SCAN_INTERVAL)
async def async_update(self):
"""Update Mikrotik Controller data."""
@ -105,9 +105,9 @@ class MikrotikControllerData():
async_dispatcher_send(self.hass, self.signal_update)
return
#---------------------------
# ---------------------------
# async_reset
#---------------------------
# ---------------------------
async def async_reset(self):
"""Reset this controller to default state."""
for unsub_dispatcher in self.listeners:
@ -116,9 +116,9 @@ class MikrotikControllerData():
self.listeners = []
return True
#---------------------------
# ---------------------------
# get_interfaces
#---------------------------
# ---------------------------
def get_interfaces(self):
ifaces = self.api.path("/interface")
for iface in ifaces:
@ -152,9 +152,9 @@ class MikrotikControllerData():
return
#---------------------------
# ---------------------------
# get_arp
#---------------------------
# ---------------------------
def get_arp(self):
self.data['arp'] = {}
if not self.option_track_arp:
@ -167,20 +167,20 @@ class MikrotikControllerData():
bridge_used = False
data = self.api.path("/ip/arp")
for entry in data:
## Ignore invalid entries
# Ignore invalid entries
if entry['invalid']:
continue
## Do not add ARP detected on bridge
# Do not add ARP detected on bridge
if entry['interface'] == "bridge":
bridge_used = True
## Build address table on bridge
# Build address table on bridge
if 'mac-address' in entry and 'address' in entry:
mac2ip[entry['mac-address']] = entry['address']
continue
## Get iface default-name from custom name
# Get iface default-name from custom name
uid = None
for ifacename in self.data['interface']:
if self.data['interface'][ifacename]['name'] == entry['interface']:
@ -190,11 +190,11 @@ class MikrotikControllerData():
if not uid:
continue
## Create uid arp dict
# Create uid arp dict
if uid not in self.data['arp']:
self.data['arp'][uid] = {}
## Add data
# Add data
self.data['arp'][uid]['interface'] = uid
if 'mac-address' in self.data['arp'][uid]:
self.data['arp'][uid]['mac-address'] = "multiple"
@ -209,24 +209,24 @@ class MikrotikControllerData():
if bridge_used:
self.update_bridge_hosts(mac2ip)
## Map ARP to ifaces
# Map ARP to ifaces
for uid in self.data['interface']:
self.data['interface'][uid]['client-ip-address'] = self.data['arp'][uid]['address'] if uid in self.data['arp'] and 'address' in self.data['arp'][uid] else ""
self.data['interface'][uid]['client-mac-address'] = self.data['arp'][uid]['mac-address'] if uid in self.data['arp'] and 'mac-address' in self.data['arp'][uid] else ""
return True
#---------------------------
# ---------------------------
# update_bridge_hosts
#---------------------------
# ---------------------------
def update_bridge_hosts(self, mac2ip):
data = self.api.path("/interface/bridge/host")
for entry in data:
## Ignore port MAC
# Ignore port MAC
if entry['local']:
continue
## Get iface default-name from custom name
# Get iface default-name from custom name
uid = None
for ifacename in self.data['interface']:
if self.data['interface'][ifacename]['name'] == entry['interface']:
@ -236,11 +236,11 @@ class MikrotikControllerData():
if not uid:
continue
## Create uid arp dict
# Create uid arp dict
if uid not in self.data['arp']:
self.data['arp'][uid] = {}
## Add data
# Add data
self.data['arp'][uid]['interface'] = uid
if 'mac-address' in self.data['arp'][uid]:
self.data['arp'][uid]['mac-address'] = "multiple"
@ -254,9 +254,9 @@ class MikrotikControllerData():
return
#---------------------------
# ---------------------------
# get_system_routerboard
#---------------------------
# ---------------------------
def get_system_routerboard(self):
data = self.api.path("/system/routerboard")
for entry in data:
@ -267,9 +267,9 @@ class MikrotikControllerData():
return
#---------------------------
# ---------------------------
# get_system_resource
#---------------------------
# ---------------------------
def get_system_resource(self):
data = self.api.path("/system/resource")
for entry in data: