def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup mFi sensors."""
    if not validate_config({DOMAIN: config},
                           {DOMAIN: ['host',
                                     CONF_USERNAME,
                                     CONF_PASSWORD]},
                           _LOGGER):
        _LOGGER.error('A host, username, and password are required')
        return False

    host = config.get('host')
    username = config.get('username')
    password = config.get('password')
    use_tls = bool(config.get(CONF_TLS, True))
    verify_tls = bool(config.get(CONF_VERIFY_TLS, True))
    default_port = use_tls and 6443 or 6080
    port = int(config.get('port', default_port))

    from mficlient.client import FailedToLogin, MFiClient

    try:
        client = MFiClient(host, username, password, port=port,
                           use_tls=use_tls, verify=verify_tls)
    except (FailedToLogin, requests.exceptions.ConnectionError) as ex:
        _LOGGER.error('Unable to connect to mFi: %s', str(ex))
        return False

    add_devices(MfiSwitch(port)
                for device in client.get_devices()
                for port in device.ports.values()
                if port.model in SWITCH_MODELS)
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/components/switch/mfi.py/setup_platform/original