From b3ef2bd2d95e2bb486c811e4aa6d4b067d0e826c Mon Sep 17 00:00:00 2001 From: carlosmgr Date: Mon, 1 Feb 2016 12:23:20 +0000 Subject: [PATCH] Update aruba.py --- .../components/device_tracker/aruba.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/device_tracker/aruba.py b/homeassistant/components/device_tracker/aruba.py index 82183e1495c..63ace67212e 100644 --- a/homeassistant/components/device_tracker/aruba.py +++ b/homeassistant/components/device_tracker/aruba.py @@ -11,7 +11,7 @@ import logging from datetime import timedelta import re import threading -import telnetlib +import pexpect from homeassistant.const import CONF_HOST, CONF_USERNAME, CONF_PASSWORD from homeassistant.helpers import validate_config @@ -94,15 +94,18 @@ class ArubaDeviceScanner(object): def get_aruba_data(self): """ Retrieve data from Aruba Access Point and return parsed result. """ try: - telnet = telnetlib.Telnet(self.host) - telnet.read_until(b'User: ') - telnet.write((self.username + '\r\n').encode('ascii')) - telnet.read_until(b'Password: ') - telnet.write((self.password + '\r\n').encode('ascii')) - telnet.read_until(b'#') - telnet.write(('show clients\r\n').encode('ascii')) - devices_result = telnet.read_until(b'#').split(b'\r\n') - telnet.write('exit\r\n'.encode('ascii')) + connect = "ssh {}@{}" + ssh = pexpect.spawn (connect.format(self.username, self.host)) + query = ssh.expect(['continue connecting (yes/no)?', 'password:']) + if query == 0: + ssh.sendline('yes') + ssh.expect ('password:') + ssh.sendline (self.password ) + ssh.expect ('#') + ssh.sendline ('show clients') + ssh.expect ('#') + devices_result = ssh.before.split(b'\r\n') + ssh.sendline ('exit') except EOFError: _LOGGER.exception("Unexpected response from router") return