""" Support for HUAWEI routers. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/device_tracker.huawei_router/ """ import base64 import logging import re from collections import namedtuple import requests import voluptuous as vol import homeassistant.helpers.config_validation as cv from homeassistant.components.device_tracker import ( DOMAIN, PLATFORM_SCHEMA, DeviceScanner) from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME _LOGGER = logging.getLogger(__name__) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Required(CONF_PASSWORD): cv.string, vol.Required(CONF_USERNAME): cv.string }) def get_scanner(hass, config): """Validate the configuration and return a HUAWEI scanner.""" scanner = HuaweiDeviceScanner(config[DOMAIN]) return scanner Device = namedtuple('Device', ['name', 'ip', 'mac', 'state']) class HuaweiDeviceScanner(DeviceScanner): """This class queries a router running HUAWEI firmware.""" ARRAY_REGEX = re.compile(r'var UserDevinfo = new Array\((.*),null\);') DEVICE_REGEX = re.compile(r'new USERDevice\((.*?)\),') DEVICE_ATTR_REGEX = re.compile( '"(?P.*?)","(?P.*?)",' '"(?P.*?)","(?P.*?)",' '"(?P.*?)","(?P.*?)",' '"(?P.*?)","(?P.*?)",' '"(?P