Esempio n. 1
0
    def __init__(self, config):
        """Initialize the scanner."""
        from tplink.tplink import TpLinkClient
        host = config[CONF_HOST]
        password = config[CONF_PASSWORD]
        username = config[CONF_USERNAME]

        self.tplink_client = TpLinkClient(password,
                                          host=host,
                                          username=username)

        self.last_results = {}
        self.success_init = self._update_info()
Esempio n. 2
0
    def __init__(self, config):
        """Initialize the scanner."""
        from tplink.tplink import TpLinkClient

        host = config[CONF_HOST]
        password = config[CONF_PASSWORD]
        username = config[CONF_USERNAME]

        self.success_init = False
        try:
            self.tplink_client = TpLinkClient(password, host=host, username=username)

            self.last_results = {}

            self.success_init = self._update_info()
        except requests.exceptions.RequestException:
            _LOGGER.debug("RequestException in %s", __class__.__name__)
Esempio n. 3
0
    def __init__(self, config):
        """Initialize the scanner."""
        from tplink.tplink import TpLinkClient
        host = config[CONF_HOST]
        password = config[CONF_PASSWORD]
        username = config[CONF_USERNAME]

        self.success_init = False
        try:
            self.tplink_client = TpLinkClient(
                password, host=host, username=username)

            self.last_results = {}

            self.success_init = self._update_info()
        except requests.exceptions.ConnectionError:
            _LOGGER.debug("ConnectionError in TplinkDeviceScanner")
class TplinkDeviceScanner(DeviceScanner):
    """Queries the router for connected devices."""
    def __init__(self, config):
        """Initialize the scanner."""
        from tplink.tplink import TpLinkClient

        host = config[CONF_HOST]
        password = config[CONF_PASSWORD]
        username = config[CONF_USERNAME]

        self.success_init = False
        try:
            self.tplink_client = TpLinkClient(password,
                                              host=host,
                                              username=username)

            self.last_results = {}

            self.success_init = self._update_info()
        except requests.exceptions.RequestException:
            _LOGGER.debug("RequestException in %s", __class__.__name__)

    def scan_devices(self):
        """Scan for new devices and return a list with found device IDs."""
        self._update_info()
        return self.last_results.keys()

    def get_device_name(self, device):
        """Get the name of the device."""
        return self.last_results.get(device)

    def _update_info(self):
        """Ensure the information from the TP-Link router is up to date.

        Return boolean if scanning successful.
        """
        _LOGGER.info("Loading wireless clients...")
        result = self.tplink_client.get_connected_devices()

        if result:
            self.last_results = result
            return True

        return False
Esempio n. 5
0
class TplinkDeviceScanner(DeviceScanner):
    """Queries the router for connected devices."""

    def __init__(self, config):
        """Initialize the scanner."""
        from tplink.tplink import TpLinkClient
        host = config[CONF_HOST]
        password = config[CONF_PASSWORD]
        username = config[CONF_USERNAME]

        self.success_init = False
        try:
            self.tplink_client = TpLinkClient(
                password, host=host, username=username)

            self.last_results = {}

            self.success_init = self._update_info()
        except requests.exceptions.ConnectionError:
            _LOGGER.debug("ConnectionError in TplinkDeviceScanner")

    def scan_devices(self):
        """Scan for new devices and return a list with found device IDs."""
        self._update_info()
        return self.last_results.keys()

    def get_device_name(self, device):
        """Get the name of the device."""
        return self.last_results.get(device)

    def _update_info(self):
        """Ensure the information from the TP-Link router is up to date.

        Return boolean if scanning successful.
        """
        _LOGGER.info("Loading wireless clients...")
        result = self.tplink_client.get_connected_devices()

        if result:
            self.last_results = result
            return True

        return False