1 """Support for Aruba Access Points."""
3 from __future__
import annotations
10 import voluptuous
as vol
13 DOMAIN
as DEVICE_TRACKER_DOMAIN,
14 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
22 _LOGGER = logging.getLogger(__name__)
24 _DEVICES_REGEX = re.compile(
25 r"(?P<name>([^\s]+)?)\s+"
26 r"(?P<ip>([0-9]{1,3}[\.]){3}[0-9]{1,3})\s+"
27 r"(?P<mac>([0-9a-f]{2}[:-]){5}([0-9a-f]{2}))\s+"
30 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
32 vol.Required(CONF_HOST): cv.string,
33 vol.Required(CONF_PASSWORD): cv.string,
34 vol.Required(CONF_USERNAME): cv.string,
39 def get_scanner(hass: HomeAssistant, config: ConfigType) -> ArubaDeviceScanner |
None:
40 """Validate the configuration and return a Aruba scanner."""
43 return scanner
if scanner.success_init
else None
47 """Class which queries a Aruba Access Point for connected devices."""
49 def __init__(self, config: dict[str, Any]) ->
None:
50 """Initialize the scanner."""
51 self.host: str = config[CONF_HOST]
52 self.username: str = config[CONF_USERNAME]
53 self.password: str = config[CONF_PASSWORD]
55 self.
last_resultslast_results: dict[str, dict[str, str]] = {}
62 """Scan for new devices and return a list with found device IDs."""
64 return [client[
"mac"]
for client
in self.
last_resultslast_results.values()]
67 """Return the name of the given device or None if we don't know."""
71 if client[
"mac"] == device:
76 """Ensure the information from the Aruba Access Point is up to date.
78 Return boolean if scanning successful.
90 """Retrieve data from Aruba Access Point and return parsed result."""
92 connect = f
"ssh {self.username}@{self.host} -o HostKeyAlgorithms=ssh-rsa"
93 ssh = pexpect.spawn(connect)
99 "continue connecting (yes/no)?",
100 "Host key verification failed.",
101 "Connection refused",
102 "Connection timed out",
107 _LOGGER.error(
"Timeout")
110 _LOGGER.error(
"Unexpected response from router")
114 ssh.expect(
"password:")
116 _LOGGER.error(
"Host key changed")
119 _LOGGER.error(
"Connection refused by server")
122 _LOGGER.error(
"Connection timed out")
124 ssh.sendline(self.password)
126 ssh.sendline(
"show clients")
128 devices_result = ssh.before.split(b
"\r\n")
131 devices: dict[str, dict[str, str]] = {}
132 for device
in devices_result:
133 if match := _DEVICES_REGEX.search(device.decode(
"utf-8")):
134 devices[match.group(
"ip")] = {
135 "ip": match.group(
"ip"),
136 "mac": match.group(
"mac").upper(),
137 "name": match.group(
"name"),
dict[str, dict[str, str]]|None get_aruba_data(self)
list[str] scan_devices(self)
str|None get_device_name(self, str device)
None __init__(self, dict[str, Any] config)
ArubaDeviceScanner|None get_scanner(HomeAssistant hass, ConfigType config)