'For each device_id listed, give the user_ip it was last seen on
Args:
user_id (str)
device_id (str): If None fetches all devices for the user
Returns:
defer.Deferred: resolves to a dict, where the keys
are (user_id, device_id) tuples. The values are also dicts, with
keys giving the column names'

@defer.inlineCallbacks
def get_last_client_ip_by_device(self, user_id, device_id):

    res = (yield self.runInteraction('get_last_client_ip_by_device', self._get_last_client_ip_by_device_txn, user_id, device_id, retcols=('user_id', 'access_token', 'ip', 'user_agent', 'device_id', 'last_seen')))
    ret = {(d['user_id'], d['device_id']): d for d in res}
    for key in self._batch_row_update:
        (uid, access_token, ip) = key
        if (uid == user_id):
            (user_agent, did, last_seen) = self._batch_row_update[key]
            if ((not device_id) or (did == device_id)):
                ret[(user_id, device_id)] = {'user_id': user_id, 'access_token': access_token, 'ip': ip, 'user_agent': user_agent, 'device_id': did, 'last_seen': last_seen}
    defer.returnValue(ret)
