def find_usbid(dev):
    """Walk pyudev device parents until USB idVendor and idProduct
       informations are found"""
    id_keys = ['idVendor', 'idProduct']
    while dev:
        attr = dev.attributes
        try:
            return tuple([int(attr.asstring(k), 16) for k in id_keys])
        except KeyError:
            dev = dev.parent