Fix mikrotik detecting capsman support (#31819)
* fix detecting capsman support * fix isort * moved support_capsman to update_devices() * moved support-checks to setup method * moved setup method to get_hub_details * implement suggestion for device lists * fix black formatting * remove not needed variable wireless_devices * fix usage of force_dhcp to seperate wireless devs * fix black fmtpull/31911/head
parent
a6eb776768
commit
20d7c84b22
|
@ -24,6 +24,7 @@ CAPSMAN = "capsman"
|
|||
DHCP = "dhcp"
|
||||
WIRELESS = "wireless"
|
||||
IS_WIRELESS = "is_wireless"
|
||||
IS_CAPSMAN = "is_capsman"
|
||||
|
||||
MIKROTIK_SERVICES = {
|
||||
ARP: "/ip/arp/getall",
|
||||
|
@ -33,6 +34,7 @@ MIKROTIK_SERVICES = {
|
|||
INFO: "/system/routerboard/getall",
|
||||
WIRELESS: "/interface/wireless/registration-table/getall",
|
||||
IS_WIRELESS: "/interface/wireless/print",
|
||||
IS_CAPSMAN: "/caps-man/interface/print",
|
||||
}
|
||||
|
||||
ATTR_DEVICE_TRACKER = [
|
||||
|
|
|
@ -27,6 +27,7 @@ from .const import (
|
|||
DHCP,
|
||||
IDENTITY,
|
||||
INFO,
|
||||
IS_CAPSMAN,
|
||||
IS_WIRELESS,
|
||||
MIKROTIK_SERVICES,
|
||||
NAME,
|
||||
|
@ -95,7 +96,8 @@ class MikrotikData:
|
|||
self.all_devices = {}
|
||||
self.devices = {}
|
||||
self.available = True
|
||||
self.support_wireless = bool(self.command(MIKROTIK_SERVICES[IS_WIRELESS]))
|
||||
self.support_capsman = False
|
||||
self.support_wireless = False
|
||||
self.hostname = None
|
||||
self.model = None
|
||||
self.firmware = None
|
||||
|
@ -135,6 +137,8 @@ class MikrotikData:
|
|||
self.model = self.get_info(ATTR_MODEL)
|
||||
self.firmware = self.get_info(ATTR_FIRMWARE)
|
||||
self.serial_number = self.get_info(ATTR_SERIAL_NUMBER)
|
||||
self.support_capsman = bool(self.command(MIKROTIK_SERVICES[IS_CAPSMAN]))
|
||||
self.support_wireless = bool(self.command(MIKROTIK_SERVICES[IS_WIRELESS]))
|
||||
|
||||
def connect_to_hub(self):
|
||||
"""Connect to hub."""
|
||||
|
@ -158,25 +162,23 @@ class MikrotikData:
|
|||
def update_devices(self):
|
||||
"""Get list of devices with latest status."""
|
||||
arp_devices = {}
|
||||
wireless_devices = {}
|
||||
device_list = {}
|
||||
wireless_devices = {}
|
||||
try:
|
||||
self.all_devices = self.get_list_from_interface(DHCP)
|
||||
if self.support_wireless:
|
||||
_LOGGER.debug("wireless is supported")
|
||||
for interface in [CAPSMAN, WIRELESS]:
|
||||
wireless_devices = self.get_list_from_interface(interface)
|
||||
if wireless_devices:
|
||||
_LOGGER.debug("Scanning wireless devices using %s", interface)
|
||||
break
|
||||
if self.support_capsman:
|
||||
_LOGGER.debug("Hub is a CAPSman manager")
|
||||
device_list = wireless_devices = self.get_list_from_interface(CAPSMAN)
|
||||
elif self.support_wireless:
|
||||
_LOGGER.debug("Hub supports wireless Interface")
|
||||
device_list = wireless_devices = self.get_list_from_interface(WIRELESS)
|
||||
|
||||
if self.support_wireless and not self.force_dhcp:
|
||||
device_list = wireless_devices
|
||||
else:
|
||||
if not device_list or self.force_dhcp:
|
||||
device_list = self.all_devices
|
||||
_LOGGER.debug("Falling back to DHCP for scanning devices")
|
||||
|
||||
if self.arp_enabled:
|
||||
_LOGGER.debug("Using arp-ping to check devices")
|
||||
arp_devices = self.get_list_from_interface(ARP)
|
||||
|
||||
# get new hub firmware version if updated
|
||||
|
|
Loading…
Reference in New Issue