mirror of
https://github.com/home-assistant/core.git
synced 2025-06-06 22:27:12 +00:00
Update aruba.py
This commit is contained in:
parent
e29a2fa45a
commit
b3ef2bd2d9
@ -11,7 +11,7 @@ import logging
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import telnetlib
|
import pexpect
|
||||||
|
|
||||||
from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD
|
||||||
from homeassistant.helpers import validate_config
|
from homeassistant.helpers import validate_config
|
||||||
@ -94,15 +94,18 @@ class ArubaDeviceScanner(object):
|
|||||||
def get_aruba_data(self):
|
def get_aruba_data(self):
|
||||||
""" Retrieve data from Aruba Access Point and return parsed result. """
|
""" Retrieve data from Aruba Access Point and return parsed result. """
|
||||||
try:
|
try:
|
||||||
telnet = telnetlib.Telnet(self.host)
|
connect = "ssh {}@{}"
|
||||||
telnet.read_until(b'User: ')
|
ssh = pexpect.spawn (connect.format(self.username, self.host))
|
||||||
telnet.write((self.username + '\r\n').encode('ascii'))
|
query = ssh.expect(['continue connecting (yes/no)?', 'password:'])
|
||||||
telnet.read_until(b'Password: ')
|
if query == 0:
|
||||||
telnet.write((self.password + '\r\n').encode('ascii'))
|
ssh.sendline('yes')
|
||||||
telnet.read_until(b'#')
|
ssh.expect ('password:')
|
||||||
telnet.write(('show clients\r\n').encode('ascii'))
|
ssh.sendline (self.password )
|
||||||
devices_result = telnet.read_until(b'#').split(b'\r\n')
|
ssh.expect ('#')
|
||||||
telnet.write('exit\r\n'.encode('ascii'))
|
ssh.sendline ('show clients')
|
||||||
|
ssh.expect ('#')
|
||||||
|
devices_result = ssh.before.split(b'\r\n')
|
||||||
|
ssh.sendline ('exit')
|
||||||
except EOFError:
|
except EOFError:
|
||||||
_LOGGER.exception("Unexpected response from router")
|
_LOGGER.exception("Unexpected response from router")
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user