'If the given device has not been registered, register it with the
supplied display name.
If no device_id is supplied, we make one up.
Args:
user_id (str):  @user:id
device_id (str | None): device id supplied by client
initial_device_display_name (str | None): device display name from
client
Returns:
str: device id (generated if none was supplied)'

@defer.inlineCallbacks
def check_device_registered(self, user_id, device_id, initial_device_display_name=None):

    if (device_id is not None):
        new_device = (yield self.store.store_device(user_id=user_id, device_id=device_id, initial_device_display_name=initial_device_display_name))
        if new_device:
            (yield self.notify_device_update(user_id, [device_id]))
        defer.returnValue(device_id)
    attempts = 0
    while (attempts < 5):
        device_id = stringutils.random_string(10).upper()
        new_device = (yield self.store.store_device(user_id=user_id, device_id=device_id, initial_device_display_name=initial_device_display_name))
        if new_device:
            (yield self.notify_device_update(user_id, [device_id]))
            defer.returnValue(device_id)
        attempts += 1
    raise errors.StoreError(500, "Couldn't    generate    a    device    ID.")
