(hass, config)
return True
Set up variables.
Set up variables.
Set up variables .
async def async_setup(hass, config):
    """Set up variables."""
    component = EntityComponent(_LOGGER, DOMAIN, hass)

    entities = []

    for variable_id, variable_config in config[DOMAIN].items():
        if not variable_config:
            variable_config = {}

        name = variable_config.get(CONF_NAME)
        value = variable_config.get(CONF_VALUE)
        attributes = variable_config.get(CONF_ATTRIBUTES)
        restore = variable_config.get(CONF_RESTORE, False)

        entities.append(
            Variable(variable_id, name, value, attributes, restore)
        )

    @asyncio.coroutine
    def async_set_variable_service(call):
        """Handle calls to the set_variable service."""
        entity_id = ENTITY_ID_FORMAT.format(call.data.get(ATTR_VARIABLE))
        entity = component.get_entity(entity_id)

        if entity:
            target_variables = [entity]
            tasks = [
                variable.async_set_variable(
                    call.data.get(ATTR_VALUE),
                    call.data.get(ATTR_VALUE_TEMPLATE),
                    call.data.get(ATTR_ATTRIBUTES),
                    call.data.get(ATTR_ATTRIBUTES_TEMPLATE),
                    call.data.get(ATTR_REPLACE_ATTRIBUTES, False),
                )
                for variable in target_variables
            ]
            if tasks:
                yield from asyncio.wait(tasks, loop=hass.loop)

        else:
            _LOGGER.warning("Failed to set unknown variable: %s", entity_id)

    hass.services.async_register(
        DOMAIN,
        SERVICE_SET_VARIABLE,
        async_set_variable_service,
        schema=SERVICE_SET_VARIABLE_SCHEMA,
    )

    await component.async_add_entities(entities)
    return True
async def async_setup ( hass , config ) : component = EntityComponent ( _LOGGER , DOMAIN , hass ) entities = [ ] for variable_id , variable_config in config [ DOMAIN ] . items ( ) : if not variable_config : variable_config = { } name = variable_config . get ( CONF_NAME ) value = variable_config . get ( CONF_VALUE ) attributes = variable_config . get ( CONF_ATTRIBUTES ) restore = variable_config . get ( CONF_RESTORE , False ) entities . append ( Variable ( variable_id , name , value , attributes , restore ) ) @ asyncio . coroutine def async_set_variable_service ( call ) : """Handle calls to the set_variable service.""" entity_id = ENTITY_ID_FORMAT . format ( call . data . get ( ATTR_VARIABLE ) ) entity = component . get_entity ( entity_id ) if entity : target_variables = [ entity ] tasks = [ variable . async_set_variable ( call . data . get ( ATTR_VALUE ) , call . data . get ( ATTR_VALUE_TEMPLATE ) , call . data . get ( ATTR_ATTRIBUTES ) , call . data . get ( ATTR_ATTRIBUTES_TEMPLATE ) , call . data . get ( ATTR_REPLACE_ATTRIBUTES , False ) , ) for variable in target_variables ] if tasks : yield from asyncio . wait ( tasks , loop = hass . loop ) else : _LOGGER . warning ( "Failed to set unknown variable: %s" , entity_id ) hass . services . async_register ( DOMAIN , SERVICE_SET_VARIABLE , async_set_variable_service , schema = SERVICE_SET_VARIABLE_SCHEMA , ) await component . async_add_entities ( entities ) return True