def setup_platform(hass, config, add_devices, discovery_info=None):
    resource = config.get('resource', None)

    try:
        response = requests.get(resource, timeout=10)
    except requests.exceptions.MissingSchema:
        _LOGGER.error("Missing resource or schema in configuration. "
                      "Add http:// to your URL.")
        return False
    except requests.exceptions.ConnectionError:
        _LOGGER.error("No route to device at %s. "
                      "Please check the IP address in the configuration file.",
                      resource)
        return False

    dev = []
    pins = config.get('pins', {})
    for pinnum, pin in pins.items():
        dev.append(ArestSwitchPin(resource,
                                  config.get('name', response.json()['name']),
                                  pin.get('name'),
                                  pinnum))

    functions = config.get('functions', {})
    for funcname, func in functions.items():
        dev.append(ArestSwitchFunction(resource,
                                       config.get('name',
                                                  response.json()['name']),
                                       func.get('name'),
                                       funcname))

    add_devices(dev)
Setup the aREST switches.
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/components/switch/arest.py/setup_platform