def setup(hass, config):
    if not isinstance(config.get(DOMAIN), dict):
        _LOGGER.error('Expected %s config to be a dictionary', DOMAIN)
        return False

    component = EntityComponent(_LOGGER, DOMAIN, hass)

    entities = []

    for object_id, cfg in config[DOMAIN].items():
        if object_id != slugify(object_id):
            _LOGGER.warning("Found invalid key for boolean input: %s. "
                            "Use %s instead", object_id, slugify(object_id))
            continue
        if not cfg:
            cfg = {}

        name = cfg.get(CONF_NAME)
        state = cfg.get(CONF_INITIAL, False)
        icon = cfg.get(CONF_ICON)

        entities.append(InputBoolean(object_id, name, state, icon))

    if not entities:
        return False

    def toggle_service(service):
        """Handle a calls to the input boolean services."""
        target_inputs = component.extract_from_service(service)

        for input_b in target_inputs:
            if service.service == SERVICE_TURN_ON:
                input_b.turn_on()
            else:
                input_b.turn_off()

    hass.services.register(DOMAIN, SERVICE_TURN_OFF, toggle_service,
                           schema=TOGGLE_SERVICE_SCHEMA)
    hass.services.register(DOMAIN, SERVICE_TURN_ON, toggle_service,
                           schema=TOGGLE_SERVICE_SCHEMA)

    component.add_entities(entities)

    return True
Apply a function to all values in a dictionary or list of dictionaries, recursively.
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/components/input_boolean.py/setup--crossover with--dataset/ETHPy150Open marshmallow-code/flask-marshmallow/flask_marshmallow/fields.py/_rapply