mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-13 02:44:31 +02:00
flake8 complaint
This commit is contained in:
parent
bb0db7f64a
commit
3b5acc2393
5 changed files with 56 additions and 55 deletions
|
@ -4,13 +4,12 @@ from .mikrotikapi import MikrotikAPI
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.helpers.event import async_track_time_interval, async_track_time_change
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
from homeassistant import config_entries
|
#from homeassistant.util import Throttle
|
||||||
from homeassistant.util import Throttle
|
|
||||||
from homeassistant.const import CONF_NAME, CONF_HOST, CONF_PORT, CONF_USERNAME, CONF_PASSWORD, CONF_SSL
|
from homeassistant.const import CONF_NAME, CONF_HOST, CONF_PORT, CONF_USERNAME, CONF_PASSWORD, CONF_SSL
|
||||||
from .const import (
|
from .const import (
|
||||||
DEFAULT_NAME,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
DATA_CLIENT,
|
DATA_CLIENT,
|
||||||
CONF_TRACK_ARP,
|
CONF_TRACK_ARP,
|
||||||
|
@ -23,6 +22,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
#DEFAULT_SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL)
|
#DEFAULT_SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL)
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# async_setup
|
# async_setup
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
@ -32,6 +32,7 @@ async def async_setup(hass, config):
|
||||||
hass.data[DOMAIN][DATA_CLIENT] = {}
|
hass.data[DOMAIN][DATA_CLIENT] = {}
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# async_setup_entry
|
# async_setup_entry
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
@ -72,6 +73,7 @@ async def async_setup_entry(hass, config_entry):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# async_unload_entry
|
# async_unload_entry
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
@ -84,6 +86,7 @@ async def async_unload_entry(hass, config_entry):
|
||||||
hass.data[DOMAIN][DATA_CLIENT].pop(config_entry.entry_id)
|
hass.data[DOMAIN][DATA_CLIENT].pop(config_entry.entry_id)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# MikrotikControllerData
|
# MikrotikControllerData
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
@ -113,7 +116,6 @@ class MikrotikControllerData():
|
||||||
async def force_update(self, now=None):
|
async def force_update(self, now=None):
|
||||||
"""Periodic update."""
|
"""Periodic update."""
|
||||||
await self.async_update()
|
await self.async_update()
|
||||||
#async_track_time_change(self.hass, self.force_update, self.option_scan_interval)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
@ -197,8 +199,8 @@ class MikrotikControllerData():
|
||||||
self.data['interface'][uid]['default-name'] = iface['default-name']
|
self.data['interface'][uid]['default-name'] = iface['default-name']
|
||||||
self.data['interface'][uid]['name'] = iface['name'] if 'name' in iface else iface['default-name']
|
self.data['interface'][uid]['name'] = iface['name'] if 'name' in iface else iface['default-name']
|
||||||
self.data['interface'][uid]['type'] = iface['type'] if 'type' in iface else "unknown"
|
self.data['interface'][uid]['type'] = iface['type'] if 'type' in iface else "unknown"
|
||||||
self.data['interface'][uid]['running'] = True if iface['running'] == True else False
|
self.data['interface'][uid]['running'] = True if iface['running'] else False
|
||||||
self.data['interface'][uid]['enabled'] = True if iface['disabled'] == False else False
|
self.data['interface'][uid]['enabled'] = True if not iface['disabled'] else False
|
||||||
self.data['interface'][uid]['port-mac-address'] = iface['mac-address'] if 'mac-address' in iface else ""
|
self.data['interface'][uid]['port-mac-address'] = iface['mac-address'] if 'mac-address' in iface else ""
|
||||||
self.data['interface'][uid]['comment'] = iface['comment'] if 'comment' in iface else ""
|
self.data['interface'][uid]['comment'] = iface['comment'] if 'comment' in iface else ""
|
||||||
self.data['interface'][uid]['last-link-down-time'] = iface['last-link-down-time'] if 'last-link-down-time' in iface else ""
|
self.data['interface'][uid]['last-link-down-time'] = iface['last-link-down-time'] if 'last-link-down-time' in iface else ""
|
||||||
|
@ -317,7 +319,7 @@ class MikrotikControllerData():
|
||||||
def get_system_routerboard(self):
|
def get_system_routerboard(self):
|
||||||
data = self.api.path("/system/routerboard")
|
data = self.api.path("/system/routerboard")
|
||||||
for entry in data:
|
for entry in data:
|
||||||
self.data['routerboard']['routerboard'] = True if entry['routerboard'] == True else False
|
self.data['routerboard']['routerboard'] = True if entry['routerboard'] else False
|
||||||
self.data['routerboard']['model'] = entry['model'] if 'model' in entry else "unknown"
|
self.data['routerboard']['model'] = entry['model'] if 'model' in entry else "unknown"
|
||||||
self.data['routerboard']['serial-number'] = entry['serial-number'] if 'serial-number' in entry else "unknown"
|
self.data['routerboard']['serial-number'] = entry['serial-number'] if 'serial-number' in entry else "unknown"
|
||||||
self.data['routerboard']['firmware'] = entry['current-firmware'] if 'current-firmware' in entry else "unknown"
|
self.data['routerboard']['firmware'] = entry['current-firmware'] if 'current-firmware' in entry else "unknown"
|
||||||
|
|
|
@ -17,8 +17,7 @@ from homeassistant.const import (
|
||||||
CONF_SSL,
|
CONF_SSL,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import (
|
from const import (
|
||||||
DEFAULT_NAME,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
CONF_TRACK_ARP,
|
CONF_TRACK_ARP,
|
||||||
DEFAULT_TRACK_ARP,
|
DEFAULT_TRACK_ARP,
|
||||||
|
@ -26,6 +25,7 @@ from .const import (
|
||||||
DEFAULT_SCAN_INTERVAL,
|
DEFAULT_SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# configured_instances
|
# configured_instances
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
@ -36,6 +36,7 @@ def configured_instances(hass):
|
||||||
entry.data[CONF_NAME] for entry in hass.config_entries.async_entries(DOMAIN)
|
entry.data[CONF_NAME] for entry in hass.config_entries.async_entries(DOMAIN)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# MikrotikControllerConfigFlow
|
# MikrotikControllerConfigFlow
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
@ -137,4 +138,3 @@ class MikrotikControllerOptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,16 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import entity_registry
|
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN
|
|
||||||
from homeassistant.components.device_tracker.config_entry import ScannerEntity
|
from homeassistant.components.device_tracker.config_entry import ScannerEntity
|
||||||
from homeassistant.components.device_tracker.const import SOURCE_TYPE_ROUTER
|
from homeassistant.components.device_tracker.const import SOURCE_TYPE_ROUTER
|
||||||
from .const import DEFAULT_NAME, DOMAIN, DATA_CLIENT, ATTRIBUTION
|
from .const import (
|
||||||
|
DOMAIN,
|
||||||
|
DATA_CLIENT,
|
||||||
|
ATTRIBUTION,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
ATTR_ATTRIBUTION,
|
ATTR_ATTRIBUTION,
|
||||||
|
@ -16,8 +19,6 @@ from homeassistant.const import (
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by Mikrotik"
|
|
||||||
|
|
||||||
DEVICE_ATTRIBUTES = [
|
DEVICE_ATTRIBUTES = [
|
||||||
"running",
|
"running",
|
||||||
"enabled",
|
"enabled",
|
||||||
|
@ -34,6 +35,7 @@ DEVICE_ATTRIBUTES = [
|
||||||
"default-name",
|
"default-name",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# async_setup_entry
|
# async_setup_entry
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
@ -41,16 +43,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up device tracker for Mikrotik Router component."""
|
"""Set up device tracker for Mikrotik Router component."""
|
||||||
name = config_entry.data[CONF_NAME]
|
name = config_entry.data[CONF_NAME]
|
||||||
mikrotik_controller = hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id]
|
mikrotik_controller = hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id]
|
||||||
tracked = {}
|
|
||||||
|
|
||||||
registry = await entity_registry.async_get_registry(hass)
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def update_controller():
|
def update_controller():
|
||||||
"""Update the values of the controller."""
|
"""Update the values of the controller."""
|
||||||
update_items(name, mikrotik_controller, async_add_entities, tracked)
|
update_items(name, mikrotik_controller, async_add_entities)
|
||||||
|
|
||||||
|
|
||||||
mikrotik_controller.listeners.append(
|
mikrotik_controller.listeners.append(
|
||||||
async_dispatcher_connect(hass, mikrotik_controller.signal_update, update_controller)
|
async_dispatcher_connect(hass, mikrotik_controller.signal_update, update_controller)
|
||||||
|
@ -59,15 +56,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
update_controller()
|
update_controller()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# update_items
|
# update_items
|
||||||
#---------------------------
|
#---------------------------
|
||||||
@callback
|
@callback
|
||||||
def update_items(name, mikrotik_controller, async_add_entities, tracked):
|
def update_items(name, mikrotik_controller, async_add_entities):
|
||||||
"""Update tracked device state from the controller."""
|
"""Update tracked device state from the controller."""
|
||||||
|
tracked = {}
|
||||||
new_tracked = []
|
new_tracked = []
|
||||||
|
|
||||||
sensors = []
|
|
||||||
for uid in mikrotik_controller.data['interface']:
|
for uid in mikrotik_controller.data['interface']:
|
||||||
if mikrotik_controller.data['interface'][uid]['type'] == "ether":
|
if mikrotik_controller.data['interface'][uid]['type'] == "ether":
|
||||||
item_id = name + "-" + mikrotik_controller.data['interface'][uid]['default-name']
|
item_id = name + "-" + mikrotik_controller.data['interface'][uid]['default-name']
|
||||||
|
@ -84,6 +82,7 @@ def update_items(name, mikrotik_controller, async_add_entities, tracked):
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# MikrotikControllerPortDeviceTracker
|
# MikrotikControllerPortDeviceTracker
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
@ -115,7 +114,6 @@ class MikrotikControllerPortDeviceTracker(ScannerEntity):
|
||||||
#await self.mikrotik_controller.async_update()
|
#await self.mikrotik_controller.async_update()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self):
|
def is_connected(self):
|
||||||
"""Return true if the port is connected to the network."""
|
"""Return true if the port is connected to the network."""
|
||||||
|
|
|
@ -5,6 +5,7 @@ import librouteros
|
||||||
import logging
|
import logging
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
#---------------------------
|
#---------------------------
|
||||||
# MikrotikAPI
|
# MikrotikAPI
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue