1 """Support for Unifi AP direct access."""
3 from __future__
import annotations
8 from unifi_ap
import UniFiAP, UniFiAPConnectionException, UniFiAPDataException
9 import voluptuous
as vol
12 DOMAIN
as DEVICE_TRACKER_DOMAIN,
13 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
21 _LOGGER = logging.getLogger(__name__)
25 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
27 vol.Required(CONF_HOST): cv.string,
28 vol.Required(CONF_PASSWORD): cv.string,
29 vol.Required(CONF_USERNAME): cv.string,
30 vol.Optional(CONF_PORT, default=DEFAULT_SSH_PORT): cv.port,
35 def get_scanner(hass: HomeAssistant, config: ConfigType) -> UnifiDeviceScanner |
None:
36 """Validate the configuration and return a Unifi direct scanner."""
38 return scanner
if scanner.update_clients()
else None
42 """Class which queries Unifi wireless access point."""
44 def __init__(self, config: ConfigType) ->
None:
45 """Initialize the scanner."""
46 self.
clientsclients: dict[str, dict[str, Any]] = {}
48 target=config[CONF_HOST],
49 username=config[CONF_USERNAME],
50 password=config[CONF_PASSWORD],
51 port=config[CONF_PORT],
55 """Scan for new devices and return a list with found device IDs."""
60 """Return the name of the given device or None if we don't know."""
63 return client_info.get(
"hostname")
67 """Update the client info from AP."""
70 except UniFiAPConnectionException
as e:
71 _LOGGER.error(
"Failed to connect to accesspoint: %s",
str(e))
73 except UniFiAPDataException
as e:
74 _LOGGER.error(
"Failed to get proper response from accesspoint: %s",
str(e))
str|None get_device_name(self, str device)
None __init__(self, ConfigType config)
bool update_clients(self)
list[str] scan_devices(self)
web.Response get(self, web.Request request, str config_key)
UnifiDeviceScanner|None get_scanner(HomeAssistant hass, ConfigType config)