mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Merge pull request #1086 from carlosmgr/dev
update SSH for aruba device tracker
This commit is contained in:
commit
077797ac4f
@ -11,7 +11,6 @@ import logging
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import telnetlib
|
|
||||||
|
|
||||||
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
|
||||||
@ -21,6 +20,7 @@ from homeassistant.components.device_tracker import DOMAIN
|
|||||||
# Return cached results if last scan was less then this time ago
|
# Return cached results if last scan was less then this time ago
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||||
|
|
||||||
|
REQUIREMENTS = ['pexpect==4.0.1']
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
_DEVICES_REGEX = re.compile(
|
_DEVICES_REGEX = re.compile(
|
||||||
@ -44,6 +44,7 @@ def get_scanner(hass, config):
|
|||||||
|
|
||||||
class ArubaDeviceScanner(object):
|
class ArubaDeviceScanner(object):
|
||||||
""" This class queries a Aruba Acces Point for connected devices. """
|
""" This class queries a Aruba Acces Point for connected devices. """
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.host = config[CONF_HOST]
|
self.host = config[CONF_HOST]
|
||||||
self.username = config[CONF_USERNAME]
|
self.username = config[CONF_USERNAME]
|
||||||
@ -93,23 +94,39 @@ 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:
|
|
||||||
telnet = telnetlib.Telnet(self.host)
|
import pexpect
|
||||||
telnet.read_until(b'User: ')
|
connect = "ssh {}@{}"
|
||||||
telnet.write((self.username + '\r\n').encode('ascii'))
|
ssh = pexpect.spawn(connect.format(self.username, self.host))
|
||||||
telnet.read_until(b'Password: ')
|
query = ssh.expect(['password:', pexpect.TIMEOUT, pexpect.EOF,
|
||||||
telnet.write((self.password + '\r\n').encode('ascii'))
|
'continue connecting (yes/no)?',
|
||||||
telnet.read_until(b'#')
|
'Host key verification failed.',
|
||||||
telnet.write(('show clients\r\n').encode('ascii'))
|
'Connection refused',
|
||||||
devices_result = telnet.read_until(b'#').split(b'\r\n')
|
'Connection timed out'], timeout=120)
|
||||||
telnet.write('exit\r\n'.encode('ascii'))
|
if query == 1:
|
||||||
except EOFError:
|
_LOGGER.error("Timeout")
|
||||||
_LOGGER.exception("Unexpected response from router")
|
|
||||||
return
|
return
|
||||||
except ConnectionRefusedError:
|
elif query == 2:
|
||||||
_LOGGER.exception("Connection refused by router," +
|
_LOGGER.error("Unexpected response from router")
|
||||||
" is telnet enabled?")
|
|
||||||
return
|
return
|
||||||
|
elif query == 3:
|
||||||
|
ssh.sendline('yes')
|
||||||
|
ssh.expect('password:')
|
||||||
|
elif query == 4:
|
||||||
|
_LOGGER.error("Host key Changed")
|
||||||
|
return
|
||||||
|
elif query == 5:
|
||||||
|
_LOGGER.error("Connection refused by server")
|
||||||
|
return
|
||||||
|
elif query == 6:
|
||||||
|
_LOGGER.error("Connection timed out")
|
||||||
|
return
|
||||||
|
ssh.sendline(self.password)
|
||||||
|
ssh.expect('#')
|
||||||
|
ssh.sendline('show clients')
|
||||||
|
ssh.expect('#')
|
||||||
|
devices_result = ssh.before.split(b'\r\n')
|
||||||
|
ssh.sendline('exit')
|
||||||
|
|
||||||
devices = {}
|
devices = {}
|
||||||
for device in devices_result:
|
for device in devices_result:
|
||||||
@ -119,5 +136,5 @@ class ArubaDeviceScanner(object):
|
|||||||
'ip': match.group('ip'),
|
'ip': match.group('ip'),
|
||||||
'mac': match.group('mac').upper(),
|
'mac': match.group('mac').upper(),
|
||||||
'name': match.group('name')
|
'name': match.group('name')
|
||||||
}
|
}
|
||||||
return devices
|
return devices
|
||||||
|
@ -114,6 +114,9 @@ orvibo==1.1.1
|
|||||||
# homeassistant.components.mqtt
|
# homeassistant.components.mqtt
|
||||||
paho-mqtt==1.1
|
paho-mqtt==1.1
|
||||||
|
|
||||||
|
# homeassistant.components.device_tracker.aruba
|
||||||
|
pexpect==4.0.1
|
||||||
|
|
||||||
# homeassistant.components.light.hue
|
# homeassistant.components.light.hue
|
||||||
phue==0.8
|
phue==0.8
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user