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)
Esempio n. 2
0
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)
Esempio n. 3
0
    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())
Esempio n. 4
0
    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'))
Esempio n. 5
0
    def test_login_fail(self, m):
        self.setup_matcher(m)

        host = '192.100.100.5'
        password = self.WRONG_PASSWORD
        quantum = QuantumGatewayScanner(host, password)

        self.assertFalse(quantum.success_init)
Esempio n. 6
0
    def test_login_success(self, m):
        self.setup_matcher(m)

        host = '192.168.1.2'
        password = self.CORRECT_PASSWORD
        quantum = QuantumGatewayScanner(host, password)

        self.assertTrue(quantum.success_init)
Esempio n. 7
0
    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.")
Esempio n. 8
0
    def __init__(self, config):
        """Initialize the scanner."""

        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 __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.")