def test_get_device_name(self, m): self.setup_matcher(m) host = '10.0.0.1' password = self.CORRECT_PASSWORD quantum = QuantumGatewayScanner(host, password) quantum.scan_devices() self.assertEqual(self.CONNECTED_DEVICES.get('00:00:00:00:00:00'), quantum.get_device_name('00:00:00:00:00:00'))
class QuantumGatewayDeviceScanner(DeviceScanner): """This class queries a Quantum Gateway.""" def __init__(self, config): """Initialize the scanner.""" from quantum_gateway import QuantumGatewayScanner self.host = config[CONF_HOST] self.password = config[CONF_PASSWORD] self.use_https = config[CONF_SSL] _LOGGER.debug('Initializing') try: self.quantum = QuantumGatewayScanner(self.host, self.password, self.use_https) self.success_init = self.quantum.success_init except RequestException: self.success_init = False _LOGGER.error("Unable to connect to gateway. Check host.") if not self.success_init: _LOGGER.error("Unable to login to gateway. Check password and " "host.") def scan_devices(self): """Scan for new devices and return a list of found MACs.""" connected_devices = [] try: connected_devices = self.quantum.scan_devices() except RequestException: _LOGGER.error("Unable to scan devices. Check connection to router") return connected_devices def get_device_name(self, device): """Return the name of the given device or None if we don't know.""" return self.quantum.get_device_name(device)
class QuantumGatewayDeviceScanner(DeviceScanner): """This class queries a Quantum Gateway.""" def __init__(self, config): """Initialize the scanner.""" from quantum_gateway import QuantumGatewayScanner self.host = config[CONF_HOST] self.password = config[CONF_PASSWORD] _LOGGER.debug('Initializing') try: self.quantum = QuantumGatewayScanner(self.host, self.password) self.success_init = self.quantum.success_init except RequestException: self.success_init = False _LOGGER.error("Unable to connect to gateway. Check host.") if not self.success_init: _LOGGER.error("Unable to login to gateway. Check password and " "host.") def scan_devices(self): """Scan for new devices and return a list of found MACs.""" connected_devices = [] try: connected_devices = self.quantum.scan_devices() except RequestException: _LOGGER.error("Unable to scan devices. Check connection to router") return connected_devices def get_device_name(self, device): """Return the name of the given device or None if we don't know.""" return self.quantum.get_device_name(device)
def test_scan_devices(self, m): self.setup_matcher(m) host = 'mywifigateway.com' password = self.CORRECT_PASSWORD quantum = QuantumGatewayScanner(host, password) devices = quantum.scan_devices() self.assertEqual(devices, self.CONNECTED_DEVICES.keys())