Switch nmap_tracker to use aiooui (#111415)
mac-vendor-lookup can take a long time to startup because it has to fetch the oui db from the webpull/111501/head
parent
9420ac1cff
commit
93cc6e0f36
|
@ -2,16 +2,14 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
from functools import partial
|
||||
import logging
|
||||
from typing import Final
|
||||
|
||||
import aiohttp
|
||||
import aiooui
|
||||
from getmac import get_mac_address
|
||||
from mac_vendor_lookup import AsyncMacLookup
|
||||
from nmap import PortScanner, PortScannerError
|
||||
|
||||
from homeassistant.components.device_tracker import (
|
||||
|
@ -158,7 +156,6 @@ class NmapDeviceScanner:
|
|||
self._known_mac_addresses: dict[str, str] = {}
|
||||
self._finished_first_scan = False
|
||||
self._last_results: list[NmapDevice] = []
|
||||
self._mac_vendor_lookup = None
|
||||
|
||||
async def async_setup(self):
|
||||
"""Set up the tracker."""
|
||||
|
@ -206,12 +203,6 @@ class NmapDeviceScanner:
|
|||
"""Signal specific per nmap tracker entry to signal a missing device."""
|
||||
return f"{DOMAIN}-device-missing-{self._entry_id}"
|
||||
|
||||
@callback
|
||||
def _async_get_vendor(self, mac_address):
|
||||
"""Lookup the vendor."""
|
||||
oui = self._mac_vendor_lookup.sanitise(mac_address)[:6]
|
||||
return self._mac_vendor_lookup.prefixes.get(oui)
|
||||
|
||||
@callback
|
||||
def _async_stop(self):
|
||||
"""Stop the scanner."""
|
||||
|
@ -227,11 +218,8 @@ class NmapDeviceScanner:
|
|||
self._scan_interval,
|
||||
)
|
||||
)
|
||||
self._mac_vendor_lookup = AsyncMacLookup()
|
||||
with contextlib.suppress((TimeoutError, aiohttp.ClientError)):
|
||||
# We don't care if this fails since it only
|
||||
# improves the data when we don't have it from nmap
|
||||
await self._mac_vendor_lookup.load_vendors()
|
||||
if not aiooui.is_loaded():
|
||||
await aiooui.async_load()
|
||||
self._hass.async_create_task(self._async_scan_devices())
|
||||
|
||||
def _build_options(self):
|
||||
|
@ -293,7 +281,7 @@ class NmapDeviceScanner:
|
|||
None,
|
||||
original_name,
|
||||
None,
|
||||
self._async_get_vendor(mac_address),
|
||||
aiooui.get_vendor(mac_address),
|
||||
"Device not found in initial scan",
|
||||
now,
|
||||
1,
|
||||
|
@ -402,7 +390,7 @@ class NmapDeviceScanner:
|
|||
continue
|
||||
|
||||
hostname = info["hostnames"][0]["name"] if info["hostnames"] else ipv4
|
||||
vendor = info.get("vendor", {}).get(mac) or self._async_get_vendor(mac)
|
||||
vendor = info.get("vendor", {}).get(mac) or aiooui.get_vendor(mac)
|
||||
name = human_readable_name(hostname, vendor, mac)
|
||||
device = NmapDevice(
|
||||
formatted_mac, hostname, name, ipv4, vendor, reason, now, None
|
||||
|
|
|
@ -7,9 +7,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/nmap_tracker",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["nmap"],
|
||||
"requirements": [
|
||||
"netmap==0.7.0.2",
|
||||
"getmac==0.9.4",
|
||||
"mac-vendor-lookup==0.1.12"
|
||||
]
|
||||
"requirements": ["netmap==0.7.0.2", "getmac==0.9.4", "aiooui==0.1.5"]
|
||||
}
|
||||
|
|
|
@ -323,6 +323,9 @@ aiooncue==0.3.5
|
|||
# homeassistant.components.openexchangerates
|
||||
aioopenexchangerates==0.4.0
|
||||
|
||||
# homeassistant.components.nmap_tracker
|
||||
aiooui==0.1.5
|
||||
|
||||
# homeassistant.components.pegel_online
|
||||
aiopegelonline==0.0.9
|
||||
|
||||
|
@ -1264,9 +1267,6 @@ lw12==0.9.2
|
|||
# homeassistant.components.scrape
|
||||
lxml==5.1.0
|
||||
|
||||
# homeassistant.components.nmap_tracker
|
||||
mac-vendor-lookup==0.1.12
|
||||
|
||||
# homeassistant.components.matrix
|
||||
matrix-nio==0.24.0
|
||||
|
||||
|
|
|
@ -296,6 +296,9 @@ aiooncue==0.3.5
|
|||
# homeassistant.components.openexchangerates
|
||||
aioopenexchangerates==0.4.0
|
||||
|
||||
# homeassistant.components.nmap_tracker
|
||||
aiooui==0.1.5
|
||||
|
||||
# homeassistant.components.pegel_online
|
||||
aiopegelonline==0.0.9
|
||||
|
||||
|
@ -1006,9 +1009,6 @@ lupupy==0.3.2
|
|||
# homeassistant.components.scrape
|
||||
lxml==5.1.0
|
||||
|
||||
# homeassistant.components.nmap_tracker
|
||||
mac-vendor-lookup==0.1.12
|
||||
|
||||
# homeassistant.components.matrix
|
||||
matrix-nio==0.24.0
|
||||
|
||||
|
|
Loading…
Reference in New Issue