@asyncio.coroutine
def async_setup(hass, config):
    'Track states and offer events for locks.'
    component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_LOCKS)
    (yield from component.async_setup(config))

    @asyncio.coroutine
    def async_handle_lock_service(service):
        'Handle calls to the lock services.'
        target_locks = component.async_extract_from_service(service)
        code = service.data.get(ATTR_CODE)
        for entity in target_locks:
            if (service.service == SERVICE_LOCK):
                (yield from entity.async_lock(code=code))
            else:
                (yield from entity.async_unlock(code=code))
        update_tasks = []
        for entity in target_locks:
            if (not entity.should_poll):
                continue
            update_coro = hass.loop.create_task(entity.async_update_ha_state(True))
            if hasattr(entity, 'async_update'):
                update_tasks.append(update_coro)
            else:
                (yield from update_coro)
        if update_tasks:
            (yield from asyncio.wait(update_tasks, loop=hass.loop))
    descriptions = (yield from hass.loop.run_in_executor(None, load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')))
    hass.services.async_register(DOMAIN, SERVICE_UNLOCK, async_handle_lock_service, descriptions.get(SERVICE_UNLOCK), schema=LOCK_SERVICE_SCHEMA)
    hass.services.async_register(DOMAIN, SERVICE_LOCK, async_handle_lock_service, descriptions.get(SERVICE_LOCK), schema=LOCK_SERVICE_SCHEMA)
    return True
Track states and offer events for locks.
@asyncio.coroutine
def async_setup(hass, config):
    
    component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_LOCKS)
    (yield from component.async_setup(config))

    @asyncio.coroutine
    def async_handle_lock_service(service):
        'Handle calls to the lock services.'
        target_locks = component.async_extract_from_service(service)
        code = service.data.get(ATTR_CODE)
        for entity in target_locks:
            if (service.service == SERVICE_LOCK):
                (yield from entity.async_lock(code=code))
            else:
                (yield from entity.async_unlock(code=code))
        update_tasks = []
        for entity in target_locks:
            if (not entity.should_poll):
                continue
            update_coro = hass.loop.create_task(entity.async_update_ha_state(True))
            if hasattr(entity, 'async_update'):
                update_tasks.append(update_coro)
            else:
                (yield from update_coro)
        if update_tasks:
            (yield from asyncio.wait(update_tasks, loop=hass.loop))
    descriptions = (yield from hass.loop.run_in_executor(None, load_yaml_config_file, os.path.join(os.path.dirname(__file__), 'services.yaml')))
    hass.services.async_register(DOMAIN, SERVICE_UNLOCK, async_handle_lock_service, descriptions.get(SERVICE_UNLOCK), schema=LOCK_SERVICE_SCHEMA)
    hass.services.async_register(DOMAIN, SERVICE_LOCK, async_handle_lock_service, descriptions.get(SERVICE_LOCK), schema=LOCK_SERVICE_SCHEMA)
    return True