mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-14 19:34:29 +02:00
flake8 compliance
This commit is contained in:
parent
d8b9294483
commit
0a6c8d369d
5 changed files with 81 additions and 82 deletions
|
@ -1,8 +1,6 @@
|
|||
"""Config flow to configure Mikrotik Router."""
|
||||
|
||||
import logging
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
import voluptuous as vol
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.core import callback
|
||||
|
@ -25,6 +23,8 @@ from .const import (
|
|||
|
||||
from .mikrotikapi import MikrotikAPI
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# ---------------------------
|
||||
# configured_instances
|
||||
# ---------------------------
|
||||
|
@ -58,16 +58,16 @@ class MikrotikControllerConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Handle a flow initialized by the user."""
|
||||
errors = {}
|
||||
if user_input is not None:
|
||||
## Check if instance with this name already exists
|
||||
# Check if instance with this name already exists
|
||||
if user_input[CONF_NAME] in configured_instances(self.hass):
|
||||
errors["base"] = "name_exists"
|
||||
|
||||
## Test connection
|
||||
# Test connection
|
||||
api = MikrotikAPI(host=user_input["host"], username=user_input["username"], password=user_input["password"], port=user_input["port"], use_ssl=user_input["ssl"])
|
||||
if not api.connect():
|
||||
errors[CONF_HOST] = api.error
|
||||
|
||||
## Save instance
|
||||
# Save instance
|
||||
if not errors:
|
||||
return self.async_create_entry(
|
||||
title=user_input[CONF_NAME],
|
||||
|
|
|
@ -49,7 +49,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
"""Update the values of the controller."""
|
||||
update_items(name, mikrotik_controller, async_add_entities, tracked)
|
||||
|
||||
|
||||
mikrotik_controller.listeners.append(
|
||||
async_dispatcher_connect(hass, mikrotik_controller.signal_update, update_controller)
|
||||
)
|
||||
|
|
|
@ -14,9 +14,9 @@ from .const import (
|
|||
DEFAULT_SCAN_INTERVAL,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
from .mikrotikapi import MikrotikAPI
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
# DEFAULT_SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL)
|
||||
|
||||
|
||||
|
@ -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,7 +209,7 @@ 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 ""
|
||||
|
@ -222,11 +222,11 @@ class MikrotikControllerData():
|
|||
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"
|
||||
|
|
|
@ -27,7 +27,7 @@ class MikrotikAPI:
|
|||
self._connected = False
|
||||
self.error = ""
|
||||
|
||||
## Default ports
|
||||
# Default ports
|
||||
if not self._port:
|
||||
self._port = 8729 if self._use_ssl else 8728
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue